Playing with VIM

A fortnight worth of tinkering and lo! my Vim looks unrecognizably different. Its behaviour, looks, everything has changed… for the better. The once empty .vimrc in my home folder (that’s Vim’s central config file, in case you don’t know) is now almost 3 pages long.. and growing fast.

I have been gobbling up all Vim-related info I could lay my hands on.. and there’s plenty to share. Let’s take it one step at a time.

First off, Vim’s key-bindings. There’s plenty up on the net for anyone out to get a decent idea of the default ones. To name a few:

And if you need more than a decent idea:

So much for defaults.. Actually a lot can be accomplished by redefining the right keys in your vimrc. Take Esc for example. It’s probably the most used key when working with Vim.. and unless you have really long fingers, it makes sense to remap it. In my case, I decided to go with ii. i to get into insert mode, ii to leave. Nifty eh? Oh but there’s more.. Check out my Vimrc (link given at end of post). Here’s a gist of the more important ones:

  • [Tab] and [Shift-Tab] do automatic keyword completion (which means you can still use Tab to insert a .. duh Tab)
  • Firefox-like Tab management (Ctrl-T to create a new Tab etc..)
  • [Ctrl-N][Ctrl-N] to toggle display of Line numbers
  • [,v] to bring up my VimRC, [,m] to bring up MRU list (requires MRU plugin)

BTW somewhere down the line, you’ll get confused between map, imap, nmap and the other map variants. When that day arrives, click here.

Alright let’s move on.. Recently I did some research on fonts for programmers and discovered that the font I was using for the past 9 years (yeah you guessed it, Courier New. I bet you use that too) while programming sucks. It can’t differentiate between 1 and l (small Ell), O and 0 (number zero) etc.. Now, I knew all that but the other fonts in my system just didn’t cut it.. (Except probably Andale Mono, but I never liked it).

Finding a better font was just a google search away, yet I never thought about it until recently. It was only then that I discovered a world of fonts designed specifically for programmers.. by programmers. Try searching for “fonts for programmers” and you’ll be surprised.

What has all this got to do with Vim? Nothing.. I just thought every programmer should know. Oh and BTW I use MonteCarlo. Bit small but perfect for my needs.

Coming back to Vim, there are some really kick-ass customizations that can be done using its various options. Here are a few from my Vimrc:

  • Indentation: Disable autoindent and enable smartindent. Also, set an autocmd to enable cindent whenever a c/c++ file is detected (refer to my Vimrc for details)
  • Enable wildmenu. Displays a sexy menu when using tab-completion in the command-line.
  • Enable autoread: Reread a file even if it has been modified outside Vim.
  • Disable toolbar: I feel it just uses up screen space. So disable it.
  • Jazz up the status bar.
  • Enable dictionary completion. Specify different dictionaries for different languages/API’s/whatever. Hint: Go to Vim’s syntax folder if you want a language’s keywords.

And finally, Vim’s plugins. There are just too many of them out there and it’s upto you to find the ones that suit your needs. Check out Vim’s script wiki.

Hot Tip: Search the net for “vimrc”, go through about 10 to 15 results and modify your Vimrc accordingly. Chances are you’ll end up with just the right options.

Hot Tip 2: Back up your vimrc at periodically. That way you’ll always have it handy.

P.S: Here’s a link to my VimRC.
VIMRC – Saurav


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s