我将如何将 HOME 键绑定为 tmux 前缀? [英] How would I go about binding the HOME key as a tmux prefix?
问题描述
有没有办法在 ~/.tmux.conf 中做到这一点?
Is there a way to do this in ~/.tmux.conf?
推荐答案
如果其他一切都配置正确,应该就像把它放在你的 .tmux.conf
中一样简单:
If everything else is configured correctly, it should be as simple as putting this in your .tmux.conf
:
set-option -g prefix Home
注意:除非您手动源"您的 .tmux.conf
,否则对文件的更改只会在 tmux 服务器重新启动.要么干净地退出所有窗格、窗口(从而关闭所有会话并让服务器退出),要么使用 tmux kill-server
,然后开始新的会话.
Note: Unless you manually "source" your .tmux.conf
, changes to the file will only take affect when the tmux server is restarted. Either cleanly exit all your panes, windows (thus closing all your sessions and letting the server exit), or use tmux kill-server
, then start a fresh session.
这仅在您的终端模拟器发送与 terminfo 数据库条目的 khome
字段匹配的转义序列时有效,TERM
值在您连接到您的 tmux 会话(即 TERM
outside of" tmux).
This will only work if your terminal emulator is sending an escape sequence that matches the khome
field of the terminfo database entry for the TERM
value in effect when you connect to your tmux session (i.e. the TERM
"outside of" tmux).
您可以通过在 cat -v
中输入 Home 键(和换行符)来验证终端模拟器发送的转义序列(您可以使用 cat>Control-C 一旦它向您显示序列).常见的响应可能是 ^[[1~
或 ^[OH
.
You can verify the escape sequence sent by your terminal emulator by typing the Home key (and a newline) into cat -v
(you can abort cat with Control-C once it shows you the sequence). Common responses might be ^[[1~
or ^[OH
.
TERM
环境变量告诉基于 terminfo 的程序(如 tmux)你的终端模拟器(据说)理解和生成什么转义序列.Home 键生成的转义序列存储在 khome
字段中.您可以使用 tput 或 infocmp 来提取字段的值(两者都使用当前的 TERM
,除非它们被赋予了覆盖终端声明).>
The TERM
environment variable tells terminfo-based programs (like tmux) what escape sequences your terminal emulator (supposedly) understands and generates. The escape sequence generated by the Home key is stored in the khome
field. You can use tput or infocmp to extract the field’s value (both use the current TERM
unless they are given an overriding terminal declaration).
tput khome | cat -v ; echo
infocmp -1 | grep -F khome
修复生成的/预期的不匹配
如果您的终端模拟器生成的转义序列与您声明的 TERM
值的 khome
条目不匹配,则可以尝试以下几种方法解决问题:
Fixing a Generated/Expected Mismatch
If the escape sequence generated by your terminal emulator does not match the khome
entry for your declared TERM
value, then there are a several things that can be done to try to fix the problem:
- 重新配置您的终端模拟器.
这可能涉及使用不同的程序、选择不同的仿真,或者只是(重新)定义按下 Home 键时它发送的序列. - 选择一个新的
TERM
值,它与您的终端模拟器发送和理解的内容更匹配. - 调整 terminfo 数据库条目以匹配您的终端仿真.
您可以使用 infocmp 来提取和现有的 terminfo 条目,并使用 tic 来编译您修改后的条目. - 告诉 tmux 调整 terminfo 数据库条目的运行时副本.
tmux 提供了terminal-overrides
选项,可用于覆盖各种TERM
值的各个 terminfo 字段.
- Reconfigure your terminal emulator.
This may involve using a different program, picking a different emulation, or just (re)defining the sequence it sends when you press the Home key. - Pick a new
TERM
value that is a better match to what your terminal emulator sends and understands. - Adjust a terminfo database entry to match your terminal emulation.
You can use infocmp to extract and existing terminfo entry and tic to compile your modified entry. - Tell tmux to adjust its runtime copies of the terminfo database entries.
tmux provides theterminal-overrides
option that can be used to override individual terminfo fields for variousTERM
values.
例如,如果您的终端模拟器不发送 Home 的序列,但您可以配置一个,并且您的 TERM
的 terminfo 条目没有 khome
场,那么你可以告诉你的终端模拟器发送 ESC [
1
~
,并使用 termname:khome=\033[1~
用于您的 terminal-overrides
值(其中 termname
是与您的 TERM 值相匹配的模式).
For example, if your terminal emulator does not send a sequence for Home, but you can configure one, and the terminfo entry for your TERM
does not have a khome
field, then you could
tell your terminal emulator to send ESC [
1
~
, and use termname:khome=\033[1~
for your terminal-overrides
value (where termname
is a pattern that suitably matches your TERM value).
例如在 .tmux.conf 中:
E.g. in .tmux.conf:
set-option -g terminal-overrides "xterm-color:khome=\033[1~"
您可以使用 tmux server-info
来检查 tmux 的 terminfo 条目的运行时副本.
You can use tmux server-info
to inspect tmux’s runtime copies of the terminfo entries.
注意:如上(使用prefix
更改),让此更改生效的最简单方法是重新启动tmux服务器.
Note: As above (with the prefix
change), the easiest way to let this change become effective is to restart your tmux server.
这篇关于我将如何将 HOME 键绑定为 tmux 前缀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!