如何在 tmux 中强制使用 emacs 样式的状态键?

Nik*_*ita 4 tmux

我在使用 tmux 1.8 时遇到了这个问题:我想将status-keys选项设置为“emacs”,因为我真的不喜欢在 vi 模式下输入命令。但是,将以下行添加到 .tmux.conf 没有任何效果:

set -g status-keys emacs
Run Code Online (Sandbox Code Playgroud)

当 tmux 重新启动时,tmux show-options -g | grep keys说emacs但实际行为是 vi 风格的。

问题的根源是$EDITOR环境变量,它vim在我的情况下设置为。文件指出:

status-keys [vi | emacs]
    Use vi or emacs-style key bindings in the status line,
    for example at the command prompt.  The default is emacs,
    unless the VISUAL or EDITOR environment variables are set
    and contain the string `vi'.
Run Code Online (Sandbox Code Playgroud)

显然,当环境变量是“vim”时,它会强制使用 vi 状态键。

尽管环境变量存在,有没有办法覆盖此行为并让提示表现 emacs 风格?我显然可以解决这个问题(比如用其他 env 变量启动 tmux 并稍后恢复原始),但我希望有一个干净的解决方案。

谢谢!

jgi*_*man 5

我遇到了这个问题,我想我只是想通了。您是否偶然也在使用 ZSH (Z Shell)?

我发现这篇文章说如果您的 VISUAL 和/或 EDITOR 设置为 vi/vim,ZSH 也会切换到“vi 模式”。所以我在 tmux 中遇到的问题实际上是从 ZSH 冒出来的!

简而言之,请确保您可以在 tmux 之外的 shell 中使用 emacs 样式的键。如果您使用的是 ZSH,您可以添加bindkey -eto.zshrc来设置 emacs 绑定。然后在.tmux.conf:

set -g mode-keys emacs
set -g status-keys emacs
Run Code Online (Sandbox Code Playgroud)


Chr*_*sen 3

如果 EDITOR 包含,则两者status-key都mode-keys默认为,但这只是默认值(在启动期间,在处理配置文件之前)。在配置中设置这些选项中的任何一个都应该覆盖基于 EDITOR 的默认值。vivi

\n\n

您是否也在设置mode-keys(控制copy-mode和choose-\xe2\x80\xa6命令中使用的键映射)?

\n\n
set -gw mode-keys emacs\n
Run Code Online (Sandbox Code Playgroud)\n

  • 我完全按照你描述的做了,但问题仍然存在。目前,我将“tmux”别名为“EDITOR= VISUAL= tmux”作为解决方法。 (3认同)