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:

  1. Press Shift-v to highlight the current line, then j, k to highlight more lines.
  2. Press gq to format text, you can use the last trick to format blocks of text.
  3. In your vimrc specify a formatprg to format your code using your favorite beautifier.
  4. zf, za fold and toggle a fold, very useful to hide long sections of code.
  5. With your cursor over a word press * or # to jump to the next or previous instance of that word in the text.
  6. In execution mode type sp then a filename to open a second file in a split window.
  7. With your cursor over a classname press gf to 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.
  8. In execution mode type sh to escape to a shell, exit that shell to return to vim.
  9. In your vimrc specify the makeprg to use ant instead of make. Try ant\ -e\ -q
  10. Press gg to jump to the top of the file and Shift-g to 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:

  1. Snippets File for Actionscript 3
  2. Automate Everyday Tasks with Ant

Leave A Comment