Hacker News new | past | comments | ask | show | jobs | submit login

These kind of articles always have a few new things in them, even of most of it is familiar -- I guess everyone just has a slightly slightly different set of indispensable tricks.

The most most useful Vim trick I've seen recently is "set relativenumber". This makes Vim show line numbers relative to the current line. This is awesome, because it lets you easily jump to any line you can see. eg. you can get to a line marked "9" above the cursor by pressing "9k".

It can be slightly tricky to get used to if you're used to absolute numbers (have to use gg more), but for me it's worth it.




I've tried relative numbers a few times in Vim, but always found it hard to adjust. But recently Jeff Kreeftmeijer wrote up a way to get the best of both worlds[1]: relative numbers in command mode and absolute numbers in insert mode or if Vim loses focus. Just another option to consider.

[1] http://jeffkreeftmeijer.com/2012/relative-line-numbers-in-vi...


That's a good hack. Personally I just have F4 mapped to toggle between relative and absolute, but relative is the default. I rarely care about specific line numbers because if I'm looking at a stack trace for something I just jump directly with :#


If you train yourself, you can get good at guessing the line numbers, plus is makes you feel godly when you correctly dd the 17 lines you want.


That, or subtracting ;)

I swear the entire UI of Vim is made to make the user feel like a ninja.


I'm fairly sure the GP meant "dd", not "add".


Ah, I meant subtracting the current line number from the target line number to get the number of lines to jump, instead of just guessing.


Got it. I think we ironically tend to underestimate our ability to estimate. I normally :set nonumber, and like secoif, I've impressed myself on numerous occasions with how well I'm able to estimate line counts and character counts. Give it a try -- you're likely to impress yourself too.


Correct.


I need to do more of this. At the moment I'm relying on visual mode way too much (i.e. select what I like, then delete it).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: