How to map key sequence to command in Vim

Vim and the thousands of plugins written for it come with commands that can be used to enable, disable, toggle or invoke an action. Typically, these commands are textual and verbose to type in. For example, the command to toggle the Gundo window is :GundoToggle

Vim is highly flexible, in that it gives you the freedom to map these commands to any key sequence you prefer. For example, I decide to I want to toggle Gundo by typing the Leader key, followed by gu. The leader key is mapped to the backslash () key.

To map this key sequence to the Gundo toggle command, add this line to your vimrc:

nnoremap <Leader>gu :GundoToggle<CR>

Note how the Vim mode for the mapping is specified (normal mode), how the Leader key is specified and how the carriage return has to be explicitly specified.

Any command can be mapped in this way to any key sequence you desire in Vim.

Tried with: Vim 7.3

Gundo plugin for Vim

Gundo is probably the coolest plugin made for Vim. Changes in Vim are tracked not in a simple linear fashion, but the entire tree of changes is maintained. So, you can actually undo back to a fork in the tree and change track to go along a different path taken earlier. This is fantastic, except it is unusable in practice since there is no way to visualize this.

Enter the fantastic Gundo plugin by Steve Losh. Install it using Pathogen and you are set. Anytime you want to see the tree of changes in Vim, use the command :GundoToggle to see a ASCII tree of changes to the left. Move up and down the tree, see a preview of the changes below and press Enter on a change to apply it live to the code to the right. You will not believe how awesome this is until you use it.

Tried with: Vim 7.3