Remap tmux prefix shortcut of control b

I tried to remap tmux prefix shortcut from control b to control / by

unbind-key C-b
set-option -g prefix C-/
bind-key C-/ send-prefix

but not fulfill the expectation, how is the correct way to accomplish it ?

Asked By: HELP ME

||

It looks like you’ve got the right idea but you’ve missed a small but important part. Here’s the process you need to follow:

First off, let’s ditch that old key binding for ‘control b’. Open your tmux config file (.tmux.conf) which is usually located in your home directory, and add the following line:

unbind C-b

This line just tells tmux to "forget" the old prefix shortcut.

Now, here’s where it gets a bit tricky. You see, your terminal might not understand ‘control /’ (C-/) the way you expect it to. So, to be safe, let’s use something like ‘control a’ (C-a) instead. Add these lines to your tmux config:

set-option -g prefix C-a
bind-key C-a send-prefix

If you’ve got your heart set on ‘control /’, you’ll have to figure out what the key code is for it in your terminal. You can do this by typing ‘control v’ followed by ‘control /’ in your terminal. It should spit out a sequence like ‘^_’. Then, in your tmux config, you can set the prefix to that sequence:

set-option -g prefix '^_'
bind-key '^_' send-prefix

Finally, you need to reload your tmux config for the changes to take effect. You can do this by running tmux source-file ~/.tmux.conf from the command line.

Answered By: ary

From man tmux:

When specifying keys, most represent themselves (for example ‘A’ to
‘Z’). Ctrl keys may be prefixed with ‘C-’ or ‘^’, and Alt (meta) with
‘M-’.

In addition, the following special key names are accepted:

Up, Down, Left, Right, BSpace, BTab, DC (Delete), End, Enter, Escape,
F1 to F20, Home, IC (Insert), NPage/PageDown/PgDn, PPage/PageUp/PgUp, Space, and Tab. Note that to bind the ‘"’ or ‘’’ keys, quotation marks are necessary […]

As you can see, a number of special keys are allowed, but / isn’t one of them. So it’s simply a case of that particular key not being bindable in tmux.

Your configuration is correct, so if you wanted to make Ctrl+x the prefix key, this would work:

unbind-key C-b
set-option -g prefix C-x
bind-key C-x send-prefix

tmux also has an advanced feature called "user-keys", where custom escape sequences can be defined and bound, but I’m not sure it will help in this case, since / isn’t an escape sequence.

Answered By: Artur Meinild
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.