运行 tmux 时映射箭头键 [英] Mapping arrow keys when running tmux

查看:45
本文介绍了运行 tmux 时映射箭头键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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 时,我看到:

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

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

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

推荐答案

Vim 知道 xterm 类终端(由以 xterm 开头的 TERM 标识,或特定响应到 t_RV 序列(如果已定义)支持某些修改键的扩展序列,但它不假定 screen 术语(您应该在 tmux).

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 并在存在 TMUX 时启用它们,并且 TERM 以 screen 开头(第一行在 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

如注释所示,您还需要启用窗口的 xterm-keys 选项.您可以像这样对所有窗口执行此操作(在您的 ~/.tmux.conf 中):

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

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

(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 时映射箭头键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆