Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force emacs-style status-keys in tmux?

Tags:

tmux

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

When tmux is restarted, tmux show-options -g | grep keys says emacs but the actual behaviour is vi-style.

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

So apparently when the environment variable is "vim" it forces vi status-keys.

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.

Thanks!

like image 263
Nikita Avatar asked Aug 14 '13 19:08

Nikita


2 Answers

I had this problem and I think I just figured it out. Are you by chance also using ZSH (Z Shell)?

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!

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
like image 109
jgillman Avatar answered Nov 12 '22 02:11

jgillman


Both status-key and mode-keys default to vi if EDITOR contains vi, but this is only a default (during startup, before the configuration files are processed). Setting either of these options in your configuration should override the EDITOR-based default.

Are you also setting mode-keys (which controls the key maps used in copy-mode, and the choose-… commands)?

set -gw mode-keys emacs
like image 25
Chris Johnsen Avatar answered Nov 12 '22 02:11

Chris Johnsen