Re:Best of Vim Tips
by bfwi on Wednesday June 25, 2014 @10:44AM
(#7944202)
Hah, I didn't think of that! Just before reading this comment I was working along in the editor, furiously pressing j/k. I'll put this to use immediately.
[ Parent
| on HN ]
Re:Best of Vim Tips
by jaredmcateer on Wednesday June 25, 2014 @11:50AM
(#7944702)
In your vimrc add the following (version 7.3+):
set number
set relativenumber
This turns your line numbers into a hybrid mode that show the numbers relative to your cursor and the actual line number your cursor is currently on.Yikes! The continually changing numbers drives me crazy. Thanks for the tip, but I think I'll stick with just using ":13" to go to line #13... I guess there is some benefit if you do a lot of yanking/cutting based on lines, rather than some magic matching or such. But for now, relative line numbers is not for me.
For (a little) more, see:
Re:Best of Vim Tips
by mediocrejoker on Wednesday June 25, 2014 @06:51PM
(#7947211)
This doesn't work for me in 7.3.429-2ubuntu2.1. It still shows 0 for the line you're currently on.
Re:Best of Vim Tips
by steveklabnik on Wednesday June 25, 2014 @04:45PM
(#7946664)
That is way cooler than my old 'focus' hack. Thank you!
Generally in vim, if you're pressing a key over and over, that's a smell that there's room for improvement there.
In addition to counting motions, other great options for getting around include:
% jump to the matching brace/bracket/paren
( jump back a "sentence"
) jump forward a "sentence"
{ jump back a "paragraph"
} jump forward a "paragraph"
Also, getting around by searching can be hugely worthwhile.Also:
n jump to the next occurrence of the last search
N " " " previous " " " " " "
* jump to the next occurrence of the word under cursor
# " " " previous " " " " " "Yes! Also, ^R^W (ctrl-r, ctrl-w) when you're at the : prompt will drop in the current word under the cursor. Which is also quite useful in keybindings.
Thanks. That's a great tip. I've always yanked the word that I wanted and then used Ctrl-R" to paste it on Vim's command line. This is much better.
I'm now off to read "cmdline.txt" (:help Command-line).
BTW, I just accidentally closed my browser tab (latest version of Firefox) by hitting Ctrl-W when I wanted to delete the previous word in this textbox. That used to drive me mad but when Firefox restored the tab, it also restored the text I'd typed. :)
might want to switch to relative line numbers. makes using 12j/k much easier in my experience.
or alternatively try the easymotion plugin[1] which you press <leader><leader>j (or whatever you map it to) and then it will highlight each potential line with a letter that you press to go to that line. j is one of the worst examples, it's nice if you are doing a dw so you don't have to count the words, you would just do d<leader><leader><motion> and it will highlight to the potential places.