top | item 4496578

Numbers.vim - A vim plugin for better line numbers

38 points| rdegges | 13 years ago |github.com | reply

20 comments

order
[+] digitaltoad|13 years ago|reply
You shouldn't ever have to count lines in vim. The five line deletion example could have been done as:

  10dG
Which would delete from the cursor to the tenth line.
[+] dhimes|13 years ago|reply
d5j

delete five from where you are- inclusive

[+] Derbasti|13 years ago|reply
Why is it better? And better than what?
[+] JamesLeonis|13 years ago|reply
There are two types of line numbering in vim, relative and absolute. The former counts the lines starting from the vertical position of the cursor, backwards and forwards. The latter starts at the top of the file to the bottom of the file.

Vim has several ways to move and edit a file. For example, to go to a specific line, you would use <n>gg and you would jump to that line. This is useful for navigation as well as selection.

There are likewise commands that are relative from the cursor's position. dd and yy come immediately to mind, as well as the h-j-k-l commands. Knowing how many lines you need is augmented from the relative line numbering.

The key here is Vim doesn't have an easy way to switch from one to the other, except through manually typing commands like `set relativenumber` and `set number`. The plugin switches the number count based on what mode you are in.

[+] city41|13 years ago|reply
I believe the general theory is relative line numbering helps you when in normal mode. If you want to manipulate a chunk of lines, sometimes you revert to counting them then doing something like <n>yy. With relative line numbering the counting is effectively done for you.

But to me, I try to avoid counting arbitrary lines and instead try and do something like y/<unique marker> or ya{ or whatever.

[+] newman314|13 years ago|reply
Does this make it so that highlighting in Terminal (prior to copying) only selects the text?

I had line numbers set till it turned out that when I selected a bunch of text for copying selected the line numbers too. Ugh.

[+] saurabh|13 years ago|reply
Can anybody tell me what relative numbers are useful for other than navigation? I find Easymotion the state-of-the-art plugin for navigation.
[+] ollysb|13 years ago|reply
Yeah, easymotion does make counting words/lines seem rather redundant. I'm just hoping that they'll extend easymotion so I don't even need to think about what I'm jumping to i.e. I hit leader leader and every non-white character is indexed to jump to.
[+] noeleon|13 years ago|reply
why not just use visual mode?? then you can see the lines you are deleting, copying / cutting