Similarly to Vim's modes, I'd like Tmux to stay in 'prefix mode' (what do you actually call it?) until I hit Escape, so that I'd be able to do something like

Prefix h j + +

instead of

Prefix h Prefix j Prefix + Prefix +

and not have to worry about timers or excessive chording.


I posted this as an issue and received this answer:

You could rebind all your keys to add switch-client -Tprefix to the end of each command sequence, but there is no automated way to do this.

The issue here is that it will not work if the command throws an error, but you can work around it by using

Yes error will cancel the command sequence you could get around this by using run-shell eg

run "tmux mycmd; tmux switch-client -Tprefix"

But that might hide the error from being displayed.

My current config looks like this:

bind c new-window \; switch-client -T prefix
bind . command-prompt \; switch-client -T prefix
bind , copy-mode \; switch-client -T prefix

# Vim style splits
bind s split-window -v \; switch-client -T prefix
bind v split-window -h \; switch-client -T prefix

# Double tab to cycle panes
bind C-a select-pane -t :.+ \; switch-client -T prefix

From what I gather, tmux uses different contexts for different bindings. To specify in which context to use a bind, you use bind <key> -T <context>, where prefix is the default. You can switch context using switch-client -T <context>, so what we do is re-apply the prefix after every command.

The drawbacks of this method are:

  • you'll have to do it explicitly on every binding
  • it'll return to normal mode if anything results in an error (e.g. trying to switch to the next session when there's only one session running)
  • it'll exit on any non-bound key, not just Esc.

Bonus! You can add a funky indicator, which is quite helpful when you're staying in prefix mode for a longer time by using something like

set -g status-right "#{?client_prefix,#[reverse]● #[noreverse],#[reverse]○ #[noreverse]}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.