Move cursor x lines from current position in vi/vim

Flawe picture Flawe · Feb 7, 2011 · Viewed 46.5k times · Source

Is there a way to move the cursor a relative amount of lines in vi/vim? Say you have the cursor 10 lines under a block of code you want to remove. If you have the line numbers shown in relative order, it would be nice to have a "jump 10 lines up command" that would take you there.

Or perhaps it's better to have the absolute line numbers shown and go xgg where x is the line number?

Answer

Cascabel picture Cascabel · Feb 7, 2011

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.