Live data from Hacker News

Better line numbers for Vim

myusuf3.github.io

11–20 of 46 posts

Re: Better line numbers for Vim

#12
My problem with relative numbering is that it doesn't seem to work correctly when a line is wrapped.

Say I want to move 6 lines down. I use 6j, but one of the lines I want to jump over is wrapped and occupies 2 lines in my editor. That will mean my cursor will end up at the line that was previous numbered 5. This behavior drives me nuts.

Re: Better line numbers for Vim

#13
post #8

I was at one point very interested in the same idea. I wanted relative line numbers and absolute line numbers integrated together. So, I created a patch, called it `dnu` for "dual line numbering", and sent the suggestion to Bram Moolenaar. Here's what it looked like: http://i.imgur.com/NTwwB.jpg Here was the patch. I wrote it back in 2011: https://code.google.com/r/justinvh-vim/source/detail?r=c2479... Ultimately Bra…

In my vim doesn't show the 0 instead it shows the line number you're currently on. Seems somewhat what you suggested.

Re: Better line numbers for Vim

#14
post #10
post #8

I was at one point very interested in the same idea. I wanted relative line numbers and absolute line numbers integrated together. So, I created a patch, called it `dnu` for "dual line numbering", and sent the suggestion to Bram Moolenaar. Here's what it looked like: http://i.imgur.com/NTwwB.jpg Here was the patch. I wrote it back in 2011: https://code.google.com/r/justinvh-vim/source/detail?r=c2479... Ultimately Bra…

This looks quite useful to me. Feature request: allow the user to select separate colors for the relative and absolute line numbers, and for the slash. So three separate colors in total. That would make it easier to read. Another idea is to have relative line numbers on the left side of the screen, and absolute line numbers on the right (or vice-versa).

I would love to take feature requests, but it's honestly not maintained. Don't get me wrong, it wouldn't be hard to reintegrate it with the current release, but I believe the idea should be at least approximated with vimscripts rather than making someone build a custom vim release to support this feature alone. Plus, now :rnu sort-of mimics this functionality by showing the current line number on the 0th row, instead of '0'.

On a side note, to your second request of left-side/right-side splits for line numbers: my first experimentation was to do just that. Left side was rnu and right side was nu, but the way vim's buffers work out, it wasn't very practical. It also caused headaches for rtl text and so on if I remember correctly.

Re: Better line numbers for Vim

#15
If it's useful to other people--and obviously it is--it was worth writing, so congratulations on shipping.

That said, put me in the category of crotchety old Vim users (even though I'm only 20) who really don't have a use for this. Potential use cases:

Scrolling: If it's a few lines, I tap j a few times--or guesstimate a number prefix. It's just scrolling--no precision needed. If it's more than a few lines, I use C-d/C-u. If I need to teleport to a line I know about, : is fine.

Yanking/Deleting/Changing/Indenting: I turn on visual line mode (V), and proceed as above. Or, depending on the language I'm in, I'll do, for example, yi{ to yank everything in the current block. Or use () judiciously.

So...what's the actual use case for this? Not trying to be critical--I just want to understand how I'd integrate it into my workflow.

Re: Better line numbers for Vim

#16
post #13
post #8

I was at one point very interested in the same idea. I wanted relative line numbers and absolute line numbers integrated together. So, I created a patch, called it `dnu` for "dual line numbering", and sent the suggestion to Bram Moolenaar. Here's what it looked like: http://i.imgur.com/NTwwB.jpg Here was the patch. I wrote it back in 2011: https://code.google.com/r/justinvh-vim/source/detail?r=c2479... Ultimately Bra…

In my vim doesn't show the 0 instead it shows the line number you're currently on. Seems somewhat what you suggested.

Indeed it does! However, that didn't come around until vim 7.3.787 was introduced. That was on 30-Jan-2013. I wrote this patch back in 2011.

Re: Better line numbers for Vim

#17
post #12

My problem with relative numbering is that it doesn't seem to work correctly when a line is wrapped. Say I want to move 6 lines down. I use 6j, but one of the lines I want to jump over is wrapped and occupies 2 lines in my editor. That will mean my cursor will end up at the line that was previous numbered 5. This behavior drives me nuts.

That shouldn't happen unless you've mapped "j" to "gj" (which is fairly common for people who use line wrapping): http://vimdoc.sf.net/htmldoc/motion.html#gj

Re: Better line numbers for Vim

#18
post #15

If it's useful to other people--and obviously it is--it was worth writing, so congratulations on shipping. That said, put me in the category of crotchety old Vim users (even though I'm only 20) who really don't have a use for this. Potential use cases: Scrolling: If it's a few lines, I tap j a few times--or guesstimate a number prefix. It's just scrolling--no precision needed. If it's more than a few lines, I use C-d…

Are you asking the use case for relative line numbers or for the plugin? For relative line numbering, the benefit I see is the ability to move with precision to specific lines without (a) switching to line-wise selection mode during visual selection, or (b) losing your horizontal cursor position, both of which are required for using the : jump. As for the plugin, it just makes switching between relative and absolute numbers conveniently automatic.

Re: Better line numbers for Vim

#19
post #9

Earlier quoted context omitted.

I didn't even realize relative numbering was a built in feature of vim - learned by reading the plugin source. Vim is the gift that keeps on giving.

I went to relative numbering a while ago and I can't go back. It's awesome. The only problem is that it's new in vim 7.3, so there are times where I'm forced to use an older version of vim and can't use the feature. I'll look up 10 lines, see "583" and automatically hit 583k without thinking. Not a big deal, and of course I can just do 583G to fix my mistake, but it's definitely some combination of funny and irritati…

This feature is exposing that my neural pathways for typing numerals above 4 are weak. Jumping 13 lines is so much easier than jumping 7... I have to actually look at the keyboard to type 7k! This will require some training.

Re: Better line numbers for Vim

#20
post #15

If it's useful to other people--and obviously it is--it was worth writing, so congratulations on shipping. That said, put me in the category of crotchety old Vim users (even though I'm only 20) who really don't have a use for this. Potential use cases: Scrolling: If it's a few lines, I tap j a few times--or guesstimate a number prefix. It's just scrolling--no precision needed. If it's more than a few lines, I use C-d…

I agree with your points, and would like to add that with EasyMotion it has even less use.
Post reply on HN