How to prevent <Esc> from waiting for more input in Insert Mode

In my case, it was tmux injecting that delay (this came as a complete surprise for me!).

I fixed it by adding set -g escape-time 0 to my tmux.conf.


This may not strictly help the author, but this question comes up first when searching for this issue with many different keyword combinations, so I hope it helps someone.


Source: first comment from here.


UPDATE (3/19/2014)

I found a far better solution than trying to hunt down all the mappings that start with <Esc>, courtesy of Powerline, from the Tips & Tricks section of the docs. Put this somewhere in your .vimrc:

 " leave insert mode quickly
  if ! has('gui_running')
    set ttimeoutlen=10
    augroup FastEscape
      autocmd!
      au InsertEnter * set timeoutlen=0
      au InsertLeave * set timeoutlen=1000
    augroup END
  endif

Note that this will make it impossible to use mappings that start with <Esc> while in insert mode, but there shouldn't be any of those anyway, because of the problem this solves.


I found the lines in spf13's .vimrc that were causing the problem:

" Fix home and end keybindings for screen, particularly on mac
" - for some reason this fixes the arrow keys too. huh.
map ^[F $
imap ^[F $
map ^[H g0
imap ^[H g0

The reason I couldn't find them before is because they weren't mapped using <Esc>, but ^[ instead. Very irritating! Hope this helps some equally disgruntled spf13 user :)

UPDATE:

If removing those mappings doesn't work, then it's probably a mapping from a plugin.

Type :verbose map <Esc> to get a list of all mappings involving Esc. The verbose part instructs Vim to print where the mapping was set. That should help find out what's causing the problem.

Also, the command unmap <Esc> might be useful—it removes any mappings for the Esc key.

Note that unmap does not remove mappings in all modes; type :h unmap for more info.