我该如何将 HOME 键绑定为 tmux 前缀?
有没有办法在 ~/.tmux.conf 中执行此操作?
Is there a way to do this in ~/.tmux.conf?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
有没有办法在 ~/.tmux.conf 中执行此操作?
Is there a way to do this in ~/.tmux.conf?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
如果其他所有内容都配置正确,则应该像将其放入
.tmux.conf
中一样简单:注意:除非您手动“获取”您的
.tmux.conf
,仅当tmux服务器重新启动时,对文件的更改才会生效。要么彻底退出所有窗格、窗口(从而关闭所有会话并让服务器退出),要么使用 tmux Kill-server,然后启动一个新会话。仅当您的终端仿真器发送的转义序列与 terminfo 数据库条目的
khome
字段相匹配(当您连接到时有效的TERM
值)时,此操作才有效。 >tmux 会话(即TERM
“外部”tmux)。为 Home 生成的转义序列
您可以通过在
cat -v
中键入 Home 键(和换行符)来验证终端仿真器发送的转义序列(您可以使用以下命令中止 cat Control-C 一旦它显示了序列)。常见响应可能是^[[1~
或^[OH
。Home 的预期转义序列
TERM
环境变量告诉基于 terminfo 的程序(例如 tmux)您的终端仿真器(假定)可以理解并生成哪些转义序列。 Home 键生成的转义序列存储在khome
字段中。您可以使用tput或infocmp来提取字段的值(两者都使用当前TERM
,除非给它们提供了覆盖终端声明)。修复生成的/预期的不匹配
如果终端仿真器生成的转义序列与声明的
TERM
值的khome
条目不匹配,则可以采取以下措施:已完成尝试解决问题:这可能涉及使用不同的程序、选择不同的仿真,或者只是(重新)定义按 Home 键时它发送的序列。
TERM
值。您可以使用 infocmp 提取现有的 terminfo 条目,并使用 tic 编译修改后的条目。
tmux 提供
terminal-overrides
选项,可用于覆盖各种TERM
值的各个 terminfo 字段。例如,如果您的终端模拟器不发送 Home 序列,但您可以配置一个序列,并且
TERM
的 terminfo 条目没有khome
字段,则你可以告诉你的终端模拟器发送 ESC
[
1
~
,并使用termname:khome=\033[1~
为您的terminal-overrides
值(其中termname
是与您的 TERM 值相匹配的模式)。例如,在 .tmux.conf 中:
您可以使用 tmux server-info 来检查 terminfo 条目的 tmux 运行时副本。
注意:如上所述(更改
前缀
),让此更改生效的最简单方法是重新启动您的tmux服务器。If everything else is configured correctly, it should be as simple as putting this in your
.tmux.conf
: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 usetmux kill-server
, then start a fresh session.This will only work if your terminal emulator is sending an escape sequence that matches the
khome
field of the terminfo database entry for theTERM
value in effect when you connect to your tmux session (i.e. theTERM
“outside of” tmux).Generated Escape Sequence for Home
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
.Expected Escape Sequence for Home
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 thekhome
field. You can use tput or infocmp to extract the field’s value (both use the currentTERM
unless they are given an overriding terminal declaration).Fixing a Generated/Expected Mismatch
If the escape sequence generated by your terminal emulator does not match the
khome
entry for your declaredTERM
value, then there are a several things that can be done to try to fix the problem: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.
TERM
value that is a better match to what your terminal emulator sends and understands.You can use infocmp to extract and existing terminfo entry and tic to compile your modified entry.
tmux provides the
terminal-overrides
option that can be used to override individual terminfo fields for variousTERM
values.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 akhome
field, then you couldtell your terminal emulator to send ESC
[
1
~
, and usetermname:khome=\033[1~
for yourterminal-overrides
value (wheretermname
is a pattern that suitably matches your TERM value).E.g. in .tmux.conf:
You can use
tmux server-info
to inspect tmux’s runtime copies of the terminfo entries.Note: As above (with the
prefix
change), the easiest way to let this change become effective is to restart your tmux server.