Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move cursor x lines from current position in vi/vim

Tags:

vim

vi

People also ask

How do you move between lines in vim?

In normal mode or in insert mode, press Alt-j to move the current line down, or press Alt-k to move the current line up. After visually selecting a block of lines (for example, by pressing V then moving the cursor down), press Alt-j to move the whole block down, or press Alt-k to move the block up.

What command do you use in vim to move the cursor down by 10 lines?

j and k move down and up one line, so 10j and 10k move down and up ten lines. You can repeat any motion by putting a number before it.


Yep, of course there's a way. j and k move down and up one line, so 10j and 10k move down and up ten lines. You can repeat any motion by putting a number before it.

You might also want to set relativenumber if this is something you do a lot of - it'll help save you counting by printing line numbers relative to the current line, instead of absolute numbers.


Moving 10 lines up and down might not suit your task as well as other options. Consider other movements:

Ctrlf, Ctrlb page forward and back.

}, { move forward and back by one paragraph.

You can write rules in your vimrc to bind 10j to a key, say J to move down 10 lines by adding the following line to your vimrc file: map <S-j> 10j

However you'd be overwriting the useful existing J command (join two lines). Finding a well positioned unused key combination for 10j/10k might be difficult, so I suggest using the existing movements that I mentioned.

You may also want to know that you can move backwards to a word that you see by doing: ?someword and forward to a word you see by doing /someword. These are going to be faster than trying to move up/down 10 lines and then repositioning your cursor to the exact location. If you cant think of a simple search string for the line in question, you can always go to the line number as you said (xgg).


I was messing with vim and I noticed - moves you up and + moves you down, so you can:

10-

or you could use k since you're most likely used to hjkl cursor movement.