These key mappings stop working in tmux. In my .vimrc
, I have:
nmap i
map j
map k
ma
Vim knows that xterm-like terminals (identified by TERM starting with xterm
, or a particular response to the t_RV
sequence, if it is defined) support extended sequences for certain modified keys, but it does not assume this for screen
TERMs (which you should be using under tmux).
You can, however tell Vim about these sequences and enable them if TMUX is present, and TERM starts with screen
(the first lines enable (better) mouse support under tmux, which you might also like):
if &term =~ '^screen' && exists('$TMUX')
set mouse+=a
" tmux knows the extended mouse mode
set ttymouse=xterm2
" tmux will send xterm-style keys when xterm-keys is on
execute "set =\e[1;*A"
execute "set =\e[1;*B"
execute "set =\e[1;*C"
execute "set =\e[1;*D"
execute "set =\e[1;*H"
execute "set =\e[1;*F"
execute "set =\e[2;*~"
execute "set =\e[3;*~"
execute "set =\e[5;*~"
execute "set =\e[6;*~"
execute "set =\e[1;*P"
execute "set =\e[1;*Q"
execute "set =\e[1;*R"
execute "set =\e[1;*S"
execute "set =\e[15;*~"
execute "set =\e[17;*~"
execute "set =\e[18;*~"
execute "set =\e[19;*~"
execute "set =\e[20;*~"
execute "set =\e[21;*~"
execute "set =\e[23;*~"
execute "set =\e[24;*~"
endif
As the comment indicates, you also need to have the window’s xterm-keys
option enabled. You can do this for all your windows like this (in your ~/.tmux.conf
):
set-option -gw xterm-keys on
(Remember that changes to ~/.tmux.conf
are not automatically loaded. To be effective, you will need to run this command manually (in a tmux
shell command, or at a Prefix :
prompt), or re-load your configuration file with source ~/.tmux.conf
(in a tmux
shell command, or at a Prefix :
prompt), or restart your server (exit all your sessions and restart tmux)).