Move x line cursor from current position to vi / vim

Is there a way to move the cursor relative to the number of lines in vi / vim? Say you have a 10-line pointer below the block of code that you want to delete. If you have line numbers shown in relative order, it would be nice to have the command "jump 10 lines up" that takes you there.

Or maybe it's better to show the absolute line numbers and go xgg, where x is the line number?

+45
vim vi
Feb 06 2018-11-11T00:
source share
3 answers
Yes, of course, there is a way. j and k move down and up along the same line, so 10j and 10k move down and up in ten lines. You can repeat any movement by putting a number in front of it.

You might also want to set relativenumber if this is what you are doing a lot - this will save you time by printing line numbers relative to the current line, instead of absolute numbers.

+63
Feb 06 '11 at 23:51
source share

Moving 10 lines up and down may not correspond to your task, as well as other parameters. Let's consider other movements:

Ctrl+f , Ctrl+b forward and backward.

} , { move forward and backward in one paragraph.

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

However, you must rewrite the useful existing J command (concatenate two lines). Finding a convenient combination of unused keys for 10j / 10k can be difficult, so I suggest using the existing movements that I talked about.

You may also know that you can move back to the word that you see ?someword and go to the word that you see by running /someword . This will be faster than trying to move up / down 10 lines and then moving the cursor to the exact location. If you are not thinking of a simple search string for a given string, you can always go to the line number, as you said ( xgg ).

+33
Feb 07 2018-11-11T00:
source share

I was messing around with vim, and I noticed that - moves you, and + moves you, so you can

 10- 

or you can use k, since you are most likely using the hjkl cursor movement.

+7
Jul 31 '14 at 17:49
source share



All Articles