Slight delay when switching modes in vim using tmux or screen
Solution 1:
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.
Solution 2:
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.
Solution 3:
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.
Solution 4:
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.