问题描述
我在使用 tmux 1.8 时遇到了这个问题:我想将 status-keys
选项设置为emacs",因为我真的不喜欢在 vi 模式下输入命令.但是,将以下行添加到 .tmux.conf 没有任何效果:
I have this problem with tmux 1.8: I want to set status-keys
option to 'emacs' because I really dislike entering commands in vi-mode. However adding the following line to .tmux.conf has no effect:
set -g status-keys emacs
tmux 重启时,tmux show-options -g |grep keys
说 emacs
但实际行为是 vi 风格的.
When tmux is restarted, tmux show-options -g | grep keys
says emacs
but the actual behaviour is vi-style.
问题的根源在于 $EDITOR
环境变量,在我的例子中它设置为 vim
.文档说明:
The root of the problem is the $EDITOR
environment variable, which it set to vim
in my case. The documentations states:
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'.
很明显,当环境变量是vim"时,它会强制使用 vi 状态键.
So apparently when the environment variable is "vim" it forces vi status-keys.
有没有办法覆盖此行为并使提示行为类似于 emacs 风格,尽管环境变量存在?我显然可以解决这个问题(比如用其他 env 变量启动 tmux 并稍后恢复原来的),但我希望有一个干净的解决方案.
Is there a way to override this behaviour and have the prompt behave emacs-style despite the environment variable? I can obviously hack around this (like starting tmux with other env variables and restoring the original later) but I hope there is a clean solution.
谢谢!
推荐答案
我遇到了这个问题,我想我刚刚想通了.您是否偶然也在使用 ZSH (Z Shell)?
I had this problem and I think I just figured it out. Are you by chance also using ZSH (Z Shell)?
我发现这篇文章 说 ZSH 也将切换到如果您的 VISUAL 和/或 EDITOR 设置为 vi/vim,则为vi 模式".所以我在 tmux 中遇到的问题实际上是从 ZSH 冒出来的!
I found this post that says that ZSH will also switch to "vi mode" if your VISUAL and/or EDITOR is set to vi/vim. So the problem I was having in tmux as actually bubbling up from ZSH!
简而言之,请确保您可以在 tmux 之外的 shell 中使用 emacs 样式的键.如果您使用 ZSH,您可以将 bindkey -e
添加到 .zshrc
以设置 emacs 绑定.然后在 .tmux.conf
:
In short, make sure you can use emacs-style keys in your shell outside of tmux. If you're using ZSH you can add bindkey -e
to .zshrc
to set emacs bindings. Then in .tmux.conf
:
set -g mode-keys emacs
set -g status-keys emacs
这篇关于如何在 tmux 中强制使用 emacs 样式的状态键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!