在运行tmux时映射箭头键。

时间:2022-05-05 17:26:27

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

这些键映射停止在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

When I run :map, I see:

当我跑:地图,我看到:

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

Yet when I hit control and an arrow key at the same time, it behaves as if no keybinding was set.

然而,当我同时点击控件和一个箭头键时,它的行为就好像没有设置键绑定一样。

1 个解决方案

#1


14  

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).

Vim知道xterm样的终端(从xterm开始,或者是对t_RV序列的特定响应,如果它被定义了)支持对某些修改键的扩展序列,但是它不认为这适用于屏幕术语(您应该在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):

但是,您可以告诉Vim这些序列,并在TMUX出现时启用它们,并且术语从屏幕开始(第一行在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

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):

正如注释所指出的,您还需要启用窗口的xterm-keys选项。你可以这样对你所有的窗户(在你的~/.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)).

(请记住更改为~/.tmux。conf不是自动加载的。为了有效,您需要手动运行这个命令(在tmux shell命令中,或者在前缀:prompt)中,或者用source ~/.tmux重新加载配置文件。conf(在tmux shell命令中,或在前缀:prompt)中,或重新启动服务器(退出所有会话并重新启动tmux))。

#1


14  

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).

Vim知道xterm样的终端(从xterm开始,或者是对t_RV序列的特定响应,如果它被定义了)支持对某些修改键的扩展序列,但是它不认为这适用于屏幕术语(您应该在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):

但是,您可以告诉Vim这些序列,并在TMUX出现时启用它们,并且术语从屏幕开始(第一行在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

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):

正如注释所指出的,您还需要启用窗口的xterm-keys选项。你可以这样对你所有的窗户(在你的~/.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)).

(请记住更改为~/.tmux。conf不是自动加载的。为了有效,您需要手动运行这个命令(在tmux shell命令中,或者在前缀:prompt)中,或者用source ~/.tmux重新加载配置文件。conf(在tmux shell命令中,或在前缀:prompt)中,或重新启动服务器(退出所有会话并重新启动tmux))。