Live data from Hacker News

Relative Line Numbers in Vim

jeffkreeftmeijer.com

21–30 of 40 posts

Re: Relative Line Numbers in Vim

#21
post #6

Rather than switching between rnu and nu, I simply have `set rnu` and absolute line number in my status line.

I use G to jump to the absolute line. When you need absolute numbers it's mostly because of an error that gave you a line number. You need to jump to it, that's all.

Re: Relative Line Numbers in Vim

#22

Is this a commonly known feature? Because I have never seen it before. I wish I had been introduced to it about 10 years ago.

I saw it in Learn Vimscript the Hard Way . I assumed it was common knowledge, since I couldn't see any other practical way to use 5j, etc, on a regular basis, but it's apparently less well-known than I thought.

Pre-vim, one would get quite proficient at judging line distances, e.g. 11yy, through practice. Mind you, that was probably helped by text being a fixed size on a serial terminal and bigger than much text today. However, I do wonder if the article is over-promoting movement by lines. Movement commands like ), }, ]], and good old / should be readily considered as well.

Re: Relative Line Numbers in Vim

#23
post #15

spf13 is a great plugin bundle for vim that got me started using relative line numbering. It's great for the lazy person who doesn't want to bother setting up all the fancy vim plugins and settings. https://github.com/spf13/spf13-vim

Lazy persons get the crap they deserve with SPF13.

Polite translation: Take the time to learn how to setup vim yourself and it will reward you 10 fold.

Re: Relative Line Numbers in Vim

#25
"Most testing libraries allow you to run a subset of tests based on their line number by running something like rspec spec/models/user_spec.rb:15."

This sounds... strange to me. When would this be an advantage over some sort of named test? e.g. `manage.py test Thing.validation_test`

Re: Relative Line Numbers in Vim

#26

"Most testing libraries allow you to run a subset of tests based on their line number by running something like rspec spec/models/user_spec.rb:15." This sounds... strange to me. When would this be an advantage over some sort of named test? e.g. `manage.py test Thing.validation_test`

> When would this be an advantage over some sort of named test?

Never. "Line number" is very obscure and prone to breaking. "I just added a comment at the top of the file... Whoops! Broke all the tests."

To quote the Zen Of Python—"explicit is better than implicit".

The article is a bit old so I wonder if that is still a common Ruby practice (if it ever was).

Re: Relative Line Numbers in Vim

#27
post #6

Rather than switching between rnu and nu, I simply have `set rnu` and absolute line number in my status line.

I use G to jump to the absolute line. When you need absolute numbers it's mostly because of an error that gave you a line number. You need to jump to it, that's all.

Also : will do that.

Re: Relative Line Numbers in Vim

#28

Earlier quoted context omitted.

Lazy persons get the crap they deserve with SPF13.

Polite translation: Take the time to learn how to setup vim yourself and it will reward you 10 fold.

Haha. Yes, that's what I meant. Thanks for your help.

I see two slightly overlapping trends:

1. Alice is intrigued by all the fuss about Vim and tries her best to wrap her head around it by reading online material and "The Fucking Manual" and getting her hands dirty. Because she knows that she can't be as productive as with her previous editor in an afternoon, she learns Vim on the side. Another benefit of that method (and one she doesn't know about at the moment) is that her commitment can be very light at the beginning: when she'll finally decide that Vim is not for her she won't lost anything. If she likes it her commitment will grow with time, as well as her ROI.

2. Bob is a lot into Twitter, blogs, Reddit and HN and he noticed a serious slant of what he perceives as the elite toward Vim (and the screenshots are pretty) so he decides to follow the herd, however weird Vim might be He installs Janus/SPF13/YADR because he has to be a part of the elite right now, no time to setup all those plugins and stuff. After a couple of coderwall posts listing his favorite plugins, Bob will notice that the elite is moving toward Sublime Text, persuade himself and try to persuade others that Vim is too old and, finally, switch.

The two trends are slightly overlapping because a few Bobs are going to turn into Alices along the way. Thankfully, because who wants Bobs in his community?

For the record, I'm a Bob turned Alice.

Re: Relative Line Numbers in Vim

#29
post #17

I used to use relative line numbers until I learned about dG. For example, I can use 8dG to delete from my cursor to (and including) line 8. Also works with yanking, e.g. 8yG.

Relative line numbers for LIFE! :D d3j (delete 3 down) and y3j (yank 3 down) do the same things, but relative. I don't even need to look at the relative numbers anymore really. For short hops I just guess. I'm right most of the times.

Absolute line numbers are more convenient for me. Relative line numbers didn't give me any advantage after I learned about the G command. That command is also useful for going to the bottom of the file (G) or to the top of the file (1G). With absolute line numbers I don't have the line numbers changing all the time, which was distracting. It's also easier to open files at a specific line.

Re: Relative Line Numbers in Vim

#30

"Most testing libraries allow you to run a subset of tests based on their line number by running something like rspec spec/models/user_spec.rb:15." This sounds... strange to me. When would this be an advantage over some sort of named test? e.g. `manage.py test Thing.validation_test`

> When would this be an advantage over some sort of named test? Never. "Line number" is very obscure and prone to breaking. "I just added a comment at the top of the file... Whoops! Broke all the tests." To quote the Zen Of Python—"explicit is better than implicit". The article is a bit old so I wonder if that is still a common Ruby practice (if it ever was).

Rspec tests aren't simply named "Thing.validation_test", they are generally full sentence descriptions of what the functionality is (eg. "A User that belongs to a valid and paid account should allow creation of projects").

The only time I've ever run specific tests by line-number is when I am working on making that single test green. In cases like that the line-number hardly ever changes (if it does, its because I've modified before filters or added a new `let`).

edit: for a bit more context: that entire string would not be typed in for the single test, it would be built from contexts.

    describe User do
      context "belongs to a valid and paid account" do
        it "should allow creation of projects" do
        end
      end
    end
Post reply on HN