Ten Vim Tricks to Live By
I’m a big fan of Vim so I figured it was time to write something about it. Vim is a text editor which really optmizes the practice of writing code. Of course it comes with a cost, namely it’s steep learning curve. Anyway, here are ten tricks which I think make the challenge worthwhile:
- Press
Shift-vto highlight the current line, then j, k to highlight more lines. - Press
gqto format text, you can use the last trick to format blocks of text. - In your vimrc specify a
formatprgto format your code using your favorite beautifier. zf,zafold and toggle a fold, very useful to hide long sections of code.- With your cursor over a word press
*or#to jump to the next or previous instance of that word in the text. - In execution mode type
spthen a filename to open a second file in a split window. - With your cursor over a classname press
gfto open the class’ file. You can map this to open in a split window, too! This requires the file to be in vim’s path. - In execution mode type
shto escape to a shell, exit that shell to return to vim. - In your vimrc specify the
makeprgto use ant instead of make. Tryant\ -e\ -q - Press
ggto jump to the top of the file andShift-gto jump to the end of the file.
There you go, 10 simple tricks which I use every day. If you’re a vim user and want to see some more tricks or your just curious feel free to check out my vimrc. Naturally, I’d love to hear any comments or about new tricks!
Related posts:
Hello, my name is Alex Schearer. I grew up in New York and currently live in Seattle. 