Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim: display relative linenumbers starting with 1

In vim, I like using relative linenumbers to see how many lines I need to yank, delete, whatever.

However, when using relative linenumbers, the current line is 0, which means, if I want to yank until the line with number 3, I have to type 4yy, which is sort of counterintuitive and is slowing me down.

Is there a way to display relative linenumbers starting with 1 instead of 0?

like image 411
Pmarcoen Avatar asked Mar 06 '12 09:03

Pmarcoen


People also ask

How do I set relative numbers in Vim?

To show line numbers in Vim, use the :set number command for absolute line numbers, :set relativenumber for relative line numbers. If both absolute and relative line numbers are enabled Vim switches to the hybrid line numbering mode.

How do I show line numbers in Vim?

Vim can display line numbers in the left margin: Press ESC key. At the : prompt type the following command to run on line numbers: set number. To turn off line numbering, type the following command at the : prompt set nonumber.

How do you set a relative number?

Relative line numbers The current line is marked 0, the ones above and below it are marked 1, and so on. " turn relative line numbers on :set relativenumber :set rnu " turn relative line numbers off :set norelativenumber :set nornu " toggle relative line numbers :set relativenumber! :set rnu!


1 Answers

I'd say, work with the system. Instead of using a 'repeat' you could modify to use the motion as intended:

y3j instead of 4yy

You'll notice that the yank command takes a motion. yy is only there as a shorcut should you not want a motion (by definition it takes the current line).

In a sense, doing 4yy is a little bit akward ('4times' take this whole line; You are relying on the fact that the implict motion is effectively multiplied by the repeat, it isn't natural since the motion was implicit).

On the plus side, you could even combine it: 4d3j (delete 3linesdown 4 times in a row, not a very useful example)

like image 165
sehe Avatar answered Oct 13 '22 00:10

sehe