Everyone of us love the shortcuts our favorite IDE has. Vim is no less and you can define whatever shortcut you need :)
How to define a shortcut in Vim
It is very easy to define a shortcut in Vim, you only need to map the key combination you one to use with the actual command you want to execute.
To map a combination you can use map or noremap (and all the variants for each mode, like imap, inoremap, nmap, nnoremap, etc...). The difference between map and noremap is that the second one is not recursive. You have a very good explanation here.
You can see an example of a shortcut definition:
This shortcut closes Vim without saving the file and can be executed by pressing the keys 'c', 'l', 'o', 's' and 'e'
The previous example is more or less a "hard code" shortcut :) A better way to map commands is using the leader variable, so you start your shortcut by pressing your leader combination.
To define your leader combination you only need to do something like this:
In this case, my leader combination is just the ',' key :)
It is important to define your leader combination because a lot of the existing plugins for Vim use it for their own shortcuts (mappings).
Ok, now that we have defined the leader, let's have a look to my actual shortcuts.
The first one I want to show you is how to change between the actual buffer and the alternative buffer (If you don't know anything about Vim buffers, take a look at this video, it is great!)
What I'm doing here is mapping ',' and '6' to ':b#
The next shortcuts are related to some plugins I use:
I just map the NERD tree to ',d' and a little bit of help every time I want to use ack (only in normal mode) :P
Then, I have two shortcut for removing the extra spaces (at the end of the line) and to change tabs with 2 spaces :)
I also have a shortcut that changes the ruby hashes (with a symbol as key) from 1.8 syntax to 1.9 syntax:
And last, but not least, I map the tab as a match bracket finder:
I probably change all of this shortcuts in the future, when I get more experience with Vim, but I hope it shows you how powerful (and customizable) Vim is :)
PS: I know that the gist are not visible on google reader. Sorry about that! I want to move my blog and fix that :)