Vim and Zsh – ESC Key Delay in Terminal Due to Alt+ Behavior

gnome-terminalkeyboardtmuxvimzsh

My terminal setup is gnome-terminal + tmux + zsh with vi bindings.

In applications like vim or even in the zsh's command line vi editing mode, I need to frequently hit the ESC key but there is a small delay before the effects of this key take place. See GNU Screen makes Vim ESC key slow

After some experimentation, I found that hitting ESC key and immediately another key (say b) has the same effect as hitting Alt+b. I don't know why this is the case (probably for legacy reasons when there was no Alt? I don't know). Either way, I have two Alt keys and I don't want this behaviour with my ESC key. I have tried with C+[ and its the same problem with that too.

I'm not sure who is responsible for this, gnome-terminal or tmux or my OS itself (Ubuntu Natty). Any ideas on how to address this would be great.

Update: I checked without tmux on a different terminal (LXTerminal) and the delay is present there too.

Best Answer

Here's an actual fix. Add the following to .tmux.conf:

set -s escape-time 0

As mentioned in the comments: The server may need to be restarted.  tmux kill-server kills the server; you may need to restart it.  Alternatively, you can reload the configuration file from the command prompt inside tmux by typing your tmux prefix (default Ctrl+B) followed by : and entering source-file ~/.tmux.conf.

Related Question