21
votes

In MacVim and terminal Vim, everything works fine and I have no problems. As soon as I jump into tmux and run Vim there, the escape key starts having a delay of about 1 second and shows up in Vim as ^[.

I'll hit the escape key to exit insert mode but around a 1 second delay will happen before Vim reacts and takes me back to normal mode.

If I type Ctrl+o to get temporarily to insert mode it immediately pops into normal mode with no delay.

If I type jj to get to normal mode (a shortcut I set) it still takes around a second. This leads me to think that the problem may be with Vim and not tmux

I've already set set -sg escape-time 0 in my tmux.conf but it hasn't helped at all.

Any ideas?

2
Are you sure you're running the same Vim binary in both cases? On my Snow Leopard system, it appears that Apple's bundled Vim doesn't have the delay, but the one that comes with MacVim does.echristopherson
Yes, I've confirmed that I'm always running MacVim.Dustin Martin
Also note that it isn't Vim in general being slow, just the Escape command. Everything else runs fast. But since Escape is used very often, it makes using Vim in tmux very frustrating.Dustin Martin
Ack, my mistake. My Vims (both Apple-supplied and MacVim) also behave exactly as you described (no pause outside of tmux/screen, but pause inside of tmux/screen). How mysterious.echristopherson

2 Answers

38
votes

See https://unix.stackexchange.com/questions/23138/esc-key-causes-a-small-delay-in-terminal-due-to-its-alt-behavior.

The issue is with a tmux escape delay. The tmux setting below should correct it:

set -s escape-time 0

4
votes

The problem is that escape is the first character of all function keys, arrows, mouse clicks (they are sent to vim by a terminal using some escape sequence), … Hence vim waits for next character at most 'ttimeoutlen' ('timeoutlen' if 'ttimeoutlen' is -1) milliseconds in order to be sure you meant pressing escape and not, for example, <F1>. There is no way to get rid of this delay, but you can narrow it down:

set timeout timeoutlen=1000 ttimeoutlen=100

. This way it will wait 1 second for you to finish the mapping, but only 0.1 second for terminal to finish sending the escape sequence.