created January 30, 2006 · complexity basic · author Matt Zyzik · version 5.7
People get tired of hitting Escape all the time to get into normal mode. Others have given advice of using Ctrl-[ or mapping CapsLock to Escape.
I now suggest using Tab to switch to normal mode.
Tab is far faster than Escape or Ctrl-[, and there is no burden of configuring every machine you use to map CapsLock to Escape.
Now that you've read my advice and decided to start using Tab for Escape, the thought arises, "how will I insert tabs?".
You can always shift lines using << and >> when in normal mode. When in insert mode, you can use Ctrl-T and Ctrl-D to do what >> and << do, respectively. I personally like to map Alt-i to insert a Tab, because it's the fastest key combination.
Enough talk; here's the setup for your vimrc:
inoremap <m-i> <tab> nnoremap <tab> <esc> vnoremap <tab> <esc>gV onoremap <tab> <esc> inoremap <tab> <esc>`^
The gV makes sure to deselect the selection; and the `^ puts the cursor back to where it was last in insert mode (so there is no going back a char when escaping to normal mode).
Comments
Vim, by default, uses ctrl-i to insert a tab character. If you use the above hint, there's no reason to introduce a new mapping with alt-i, just restore the default mapping by putting it after all the tab remappings:
nnoremap <tab> <esc> vnoremap <tab> <esc>gV onoremap <tab> <esc> inoremap <tab> <esc>`^ inoremap <C-I> <tab>
The best way to leave insert mode:
imap jj <Esc>