我该如何将 HOME 键绑定为 tmux 前缀?

发布于 2024-12-12 16:15:04 字数 34 浏览 2 评论 0原文

有没有办法在 ~/.tmux.conf 中执行此操作?

Is there a way to do this in ~/.tmux.conf?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魔法唧唧 2024-12-19 16:15:05

如果其他所有内容都配置正确,则应该像将其放入 .tmux.conf 中一样简单:

set-option -g prefix Home

注意:除非您手动“获取”您的 .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 字段中。您可以使用tputinfocmp来提取字段的值(两者都使用当前TERM,除非给它们提供了覆盖终端声明)。

tput khome | cat -v ; echo
infocmp -1 | grep -F khome

修复生成的/预期的不匹配

如果终端仿真器生成的转义序列与声明的 TERM 值的 khome 条目不匹配,则可以采取以下措施:已完成尝试解决问题:

  1. 重新配置您的终端模拟器。
    这可能涉及使用不同的程序、选择不同的仿真,或者只是(重新)定义按 Home 键时它发送的序列。
  2. 选择一个与终端模拟器发送和理解的内容更匹配的新 TERM 值。
  3. 调整 terminfo 数据库条目以匹配您的终端仿真。
    您可以使用 infocmp 提取现有的 terminfo 条目,并使用 tic 编译修改后的条目。
  4. 告诉 tmux 调整 terminfo 数据库条目的运行时副本。
    tmux 提供 terminal-overrides 选项,可用于覆盖各种 TERM 值的各个 terminfo 字段。

例如,如果您的终端模拟器不发送 Home 序列,但您可以配置一个序列,并且 TERM 的 terminfo 条目没有 khome 字段,则你可以
告诉你的终端模拟器发送 ESC [ 1 ~,并使用 termname:khome=\033[1~为您的 terminal-overrides 值(其中 termname 是与您的 TERM 值相匹配的模式)。

例如,在 .tmux.conf 中:

set-option -g terminal-overrides "xterm-color:khome=\033[1~"

您可以使用 tmux server-info 来检查 terminfo 条目的 tmux 运行时副本。

注意:如上所述(更改前缀),让此更改生效的最简单方法是重新启动您的tmux服务器。

If everything else is configured correctly, it should be as simple as putting this in your .tmux.conf:

set-option -g prefix Home

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.

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

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

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:

  1. 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.
  2. Pick a new TERM value that is a better match to what your terminal emulator sends and understands.
  3. 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.
  4. Tell tmux to adjust its runtime copies of the terminfo database entries.
    tmux provides the terminal-overrides option that can be used to override individual terminfo fields for various TERM 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 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).

E.g. in .tmux.conf:

set-option -g terminal-overrides "xterm-color:khome=\033[1~"

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文