45

When I press the prefix-key Ctrl-b tmux doesn't give me a hint that it has been pressed.

Sometimes I can not remember whether I have already pressed it or not.

Can I set up a hint like highlight/change color or show some special symbol in the status bar to show me when I have pressed the prefix-key?

Rob Kielty
  • 7,958
  • 8
  • 39
  • 51
worldterminator
  • 2,968
  • 6
  • 33
  • 52
  • There is nothing like this built into *tmux*, but it [came up](http://thread.gmane.org/gmane.comp.terminal-emulators.tmux.user/3121) on the mailing list recently. Nothing has been incorporated into the main source yet though. – Chris Johnsen Aug 18 '12 at 05:43

3 Answers3

66

The development version of tmux has support for this, so the next release (1.8?) should also support it.

There have been two changes that can be combined to indicate in your status line whether a prefix key has been pressed:

  • You can include the extended “format” replacements in the values of the “status” options. These replacements were first available in tmux 1.6, but they were not previously usable in the status options.
  • The client_prefix format replacement was added.

You could add a (conditional) highlighted <Prefix> string before the default status-right like this:

set -g status-right ' #{?client_prefix,#[reverse]<Prefix>#[noreverse] ,}"#{=21:pane_title}" %H:%M %d-%b-%y'
Chris Johnsen
  • 214,407
  • 26
  • 209
  • 186
  • 1
    What's the meaning of the `"#22T"`? In my computer it literally shows this code in the tmux's status bar and removing it seems harmless. – luizs81 May 04 '16 at 17:24
  • 2
    `#T` is the short version of `#{pane_title}`. The intervening number used to limit the length of the substituted value (so `#22T` would only show the first 22 characters of `pane_title` if it was too long). It was part of the (old) default value of `status-right`. The newer `#{var_name}` substitution syntax uses a different length-limiting syntax: `#{=NN:var_name}`. At some point support for the old length-limiting syntax must have been dropped. In modern *tmux* the default `status-right` uses `#{=21:pane_title}`. I’ll update the answer. – Chris Johnsen May 04 '16 at 19:17
  • 1
    Also, here is how you can inspect the default value of a setting: `tmux -L none -f /dev/null start-server\; show-options -g status-right` (where `none` is a currently unused *tmux* server socket name). – Chris Johnsen May 04 '16 at 19:22
  • 2
    I use the following for displaying it on the left side of the status bar (in case anyone else was wondering): `set -g status-left '#{?client_prefix,#[reverse]#[noreverse] ,}[#S] '` – rob Mar 14 '18 at 22:10
  • This was really helpful. – Vinn Apr 18 '22 at 01:46
6

There's also a Tmux plugin called tmux-prefix-highlight that does this.
It adds a new keyword, #{prefix_highlight} to use in the string that defines your tmux status bar, like so:

set -g status-right '#{prefix_highlight} | %a %Y-%m-%d %H:%M'
arainone
  • 1,928
  • 17
  • 28
6

I created plugin for this. It indicates copy mode as well, is easily customizable and has good out-of-the-box experience.

https://github.com/dominikduda/tmux_mode_indicator

As readme says:

Plugin indicating normal/insert/prefix/copy modes.

It adds a new keyword, #{tmux_mode_indicator} to use in the string that defines your tmux status bar. Like this:

set -g status-right "#{tmux_mode_indicator}"
dominikduda
  • 325
  • 3
  • 16