John Hawthorn

Eliminating delays on ESC in vim and zsh

While having a vim discussion on twitter with @_jaredn, I remembered that having a delay in entering normal mode after pressing ESC (switching to normal mode) really frustrates me. This delay exists because many keys (arrows keys, ALT) rely on it as an escape character. Here’s the setup I’ve used for a while for near instantaneous switch into normal mode.


A simple solution for vim is to :set esckeys. However, this will break any sequences using escape in insert mode.

Another solution is to use timeoutlen and ttimeoutlen. timeoutlen is used for mapping delays, and ttimeoutlen is used for key code delays. My .vimrc has:

set timeoutlen=1000 ttimeoutlen=0

It might be more reasonable to give ttimeoutlen a more reasonable value, like 10ms, although I have encountered no issues yet.

This is especially nice with vim-powerline, which gives clear visual indication of the current mode.


ZSH uses the KEYTIMEOUT parameter to determine how long to wait (in hundredths of a second) for additional characters in sequence. Default is 0.4 seconds.

# 10ms for key sequences KEYTIMEOUT=1


tmux may also be waiting for escape characters. As per this answer on StackExchange, this can be solved by adding the following to .tmux.conf

set -s escape-time 0

Thanks to @ronjouch for pointing this out.