Mapping arrow keys when running tmux

前端 未结 1 2004
失恋的感觉
失恋的感觉 2021-02-15 20:56

These key mappings stop working in tmux. In my .vimrc, I have:

nmap  i
map  j
map  k
ma         


        
相关标签:
1条回答
  • 2021-02-15 21:35

    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 <xUp>=\e[1;*A"
        execute "set <xDown>=\e[1;*B"
        execute "set <xRight>=\e[1;*C"
        execute "set <xLeft>=\e[1;*D"
        execute "set <xHome>=\e[1;*H"
        execute "set <xEnd>=\e[1;*F"
        execute "set <Insert>=\e[2;*~"
        execute "set <Delete>=\e[3;*~"
        execute "set <PageUp>=\e[5;*~"
        execute "set <PageDown>=\e[6;*~"
        execute "set <xF1>=\e[1;*P"
        execute "set <xF2>=\e[1;*Q"
        execute "set <xF3>=\e[1;*R"
        execute "set <xF4>=\e[1;*S"
        execute "set <F5>=\e[15;*~"
        execute "set <F6>=\e[17;*~"
        execute "set <F7>=\e[18;*~"
        execute "set <F8>=\e[19;*~"
        execute "set <F9>=\e[20;*~"
        execute "set <F10>=\e[21;*~"
        execute "set <F11>=\e[23;*~"
        execute "set <F12>=\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)).

    0 讨论(0)
提交回复
热议问题