代码之家  ›  专栏  ›  技术社区  ›  Rose Perrone

运行tmux时映射箭头键

  •  8
  • Rose Perrone  · 技术社区  · 13 年前

    这些键映射在tmux中停止工作。在我的 .vimrc ,我已经:

    nmap <Space> i
    map <C-Down> <C-w>j
    map <C-Up> <C-w>k
    map <C-Left> <C-w>h
    map <C-Right> <C-w>l
    

    当我跑步时 :map ,我明白了:

       <C-Right>     <C-W>l
       <C-Left>      <C-W>h
       <C-Up>        <C-W>k
       <C-Down>      <C-W>j
    

    然而,当我同时按下控制键和箭头键时,它的行为就像没有设置键绑定一样。

    1 回复  |  直到 13 年前
        1
  •  15
  •   Chris Johnsen    13 年前

    Vim知道 xterm公司 -类似终端(以TERM开头 xterm ,或对 t_RV 序列,如果定义的话)支持某些修改键的扩展序列,但它不认为 screen TERM(您应该在下使用 tmux公司 ).

    然而,如果存在TMUX,并且TERM以 屏幕 (第一行启用了(更好的)鼠标支持 tmux公司 ,您可能也喜欢):

    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
    

    正如注释所示,您还需要有窗口 xterm-keys 选项已启用。你可以对所有的窗口都这样做(在你的 ~/.tmux.conf ):

    set-option -gw xterm-keys on
    

    (请记住,更改为 ~/.tmux.conf 不会自动加载。为了有效,您需要手动运行此命令(在 tmux shell命令,或在前缀处 : 提示),或使用重新加载配置文件 source ~/.tmux.conf (在 tmux公司 shell命令,或在前缀处 : 提示),或重新启动服务器(退出所有会话并重新启动 tmux公司 )).