64

Switching to and from insert mode in Vim is no longer instantaneous since I use tmux. After pressing Esc in insert mode, it takes a noticeable amount of time to actually get out of insert mode. After pressing Esc and any other key afterwards the switch is immediate, and the command for the key pressed after Esc is executed. Any idea what might cause this?

The Vim configuration is not the problem as the delay does not occur when I run Vim outside tmux, so this is probably related to tmux somehow. I use gnome-terminal btw.

Also worth noting, it seems I can not define key bindings in tmux for Esc, my plan was to bind Esc to:

bind Escape send-keys ^[

Alas, it seems binding anything to Esc for tmux does not work. The same problem occurs in screen as well.

118

After plowing through the man pages it turns out tmux has an option for this. The following in ~/.tmux.conf fixes the delay problem:

 set -sg escape-time 0

You have to restart your tmux server or reload your config for this to take effect. To do this, issue source-file ~/.tmux.conf from the tmux prompt.

  • 2
    Where did you find this? I can't find escape-time anywhere in man tmux, and the command doesn't work for me. – djeikyb Apr 5 '11 at 15:41
  • I suspect is is only available in the development version. You can get it here: github.com/ThomasAdam/tmux – Ton van den Heuvel Apr 5 '11 at 16:15
  • I love everything about you for this answer. This just solved an obscure emacs problem for me and now I can go to bed finally! – Bo Jeanes Aug 19 '12 at 5:13
  • 4
    I had to use tmux kill-server before this setting worked for me. Thanks! – Sam Sep 8 '13 at 15:46
  • 1
    This makes me wish I could give you 10 upvotes. Found this after an hour of battling timeouts in vim. Thank you! – malvim Jul 11 '14 at 14:30
3

I had a different but similar issue that I was trying to solve when I found this page, so I'll post that here in case it's helpful to anyone else who is in search of this answer and finds this page in the same way.

Problem: vi mode in bash has a delay when switching from insert mode to command mode

Solution: In your ~/.inputrc file, add set keyseq-timeout n where n is some low value greater than 0. n defaults to 500ms, which is what causes the delay. See documentation here.

Also, if you want to be able to tell which mode you're in, check out Dylan Cali's fork of bash.

  • that is very helpful, i set it to 0.01 and now its pleasingly much more faster. thanks! – w17t May 17 '17 at 7:28
  • It could also be appended into /etc/inputrc to make it available for all users. – w17t May 17 '17 at 8:27
1

It sounds like you are using a mapping that starts with ESC. When you press the ESC, vim has to wait to see if the next key is the one in the mapping. If it is not, it can immediately continue.

The vim configuration can be terminal dependent, so the fact that it does not happen outside of tmux does not mean much. Vim can query the $TERM environment variable and choose different configuration depending on its value.

Since gnome-terminal uses, AFAIK, xterm as the value of the $TERM variable, and tmux uses screen, I would look through all your vim configuration files for settings that are only used is the $TERM variable is equal to screen. My guess is that some vim config file on your system sets mappings for handling of arrow keys (those start with the ESC character) when the terminal is screen.

You can test it by temporarily changing the $TERM variable in tmux before starting vim. If your shell is bash, call vim as

TERM=xterm vim

in tmux and see if the problem persists. You sould not use that as a fix, though, since there may be differences between the terminal capabilities of tmux and xterm, and you may run into some problems.

  • Some good pointers here. I do use bash, but unfortunately TERM=xterm vim did not fix the problem. I'll have to dig a little deeper. – Ton van den Heuvel Mar 2 '11 at 21:13
1

As the title mentions Screen, here is the solution to fix the behaviour of Escape key within GNU Screen. (Taken from here.)

Add

maptimeout 5

to .screenrc config file.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.