I've got tmux setup just the way I like it, and my chosen key of prefix is `, because it's so quick and easy to use.
Everything was gravy until I tried using tmux from my phone, which doesn't have a ` key. Is there anyway to additionally bind ^a to the prefix, so I can use BOTH combos at the same time?
Starting with tmux 1.6, you can use the session option prefix2 to specify a second prefix key (e.g. in ~/.tmux.conf):
set-option -g prefix `
set-option -g prefix2 C-a
Note: If you have any bindings or script that use the send-prefix, you can use its -2 option to send the key assigned to prefix2: send-prefix -2.
Prior to tmux 1.6, the prefix option accepted a comma-separated list of keys:
set-option -g prefix `,C-a
Related
What does the following section do in the tmux config file?
# remap prefix
unbind C-b
set -g prefix C-a
bind C-a send-prefix
I know functionally it is changing the prefix mapping of C-b to C-a, but why does this require three lines to do that?
It seems to me the unbind removes the default C-b as prefix. But then how do the other two work? (Also, is the last line necessary?)
The first two lines unbind and set do the prefix remapping.
The last line is necessary, even though without it, you can already use c-a as prefix key.
Imagine, now your prefix is c-a, now you open vim in a tmux window, you want to increment a number by c-a, how can you do it? When you pressed c-a tmux will capture it as the tmux prefix, now you need some key to send the original c-a to the process(vim).
Same example when you edit command line with emacs binding. You want your cursor to move to the BOL by c-a.
The last line will allow a process to accept c-a in tmux window, by pressing c-a twice.
As an addition to Kent's aswer, you actually don't need unbind C-b since you can only have one main prefix. So basically you only need two lines to remap a prefix key.
This is my .tmux.conf file, placed in the home directory.
unbind C-b
set -g prefix S-a
bind S-a send-prefix
bind r source-file ~/.tmux.conf
I am properly loading it with tmux source-file ~/.tmux.conf. However, doing shift+a to initiate the prefix doesn't work.
However if I replace S-a with C-a, it'll work (ctrl+a).
What am I doing wrong?
You can't and it's not a good idea, the shift key is by no way meant for that. Take a look in the man tmux, section KEY BINDINGS for the list of available keys. More info are available here https://unix.stackexchange.com/a/140010
Solution 1
Run: (WARN: Save your work in all sessions first)
tmux kill-server
Solution 2
In your .zshrc/.bashrc file, add the following line:
[ -z "${TMUX}" ] || tmux YOUR_COMMAND
e.g. YOUR_COMMAND = set -g prefix S-a.
I want unbind the prefix keys of tmux, use caps lock-a instead of Ctrl-B
So, C means Ctrl, and ??? refer to caps lock?
unbind C-b
set -g prefix ???-a
tmux source-file ~/.tmux.conf
This is kind of a hack but achieves the end goal.
Change the behaviour of Capslock to Ctrl and keep the tmux config as C-a.
In OSX this can done using System Preferences > Keyboard > Modifier Keys.
In Linux this can be done using the command 'setxkbmap'
I use vim, and so I wanted to change a couple of tmux's default bindings. In particular I wanted to change the resizing commands so that e.g. ctrl-b ctrl-k resize the split up by one position. I entered the following into my .tmux.conf:
bind-key C-k resizep -U
and it works, except that it only allows me to resize by one unit at a time before I have to hit ctrl again. In other words, I can't hold down ctrl and press b followed by k a bunch of times (while still holding down ctrl), whereas I can hold down ctrl, press b, and then press the up arrow key a bunch of times.
Does anyone know exactly why this is, or how I might replicate my desired behavior?
You need to specify the -r parameter in your command:
bind-key -r C-k resizep -U
As explained in tmux man page:
bind-key [-cnr] [-t mode-table] key command [arguments]
(alias: bind)
Bind key key to command. By default (without -t) the primary
key bindings are modified (those normally activated with the
prefix key); in this case, if -n is specified, it is not necesā
sary to use the prefix key, command is bound to key alone. The
-r flag indicates this key may repeat, see the repeat-time
option.
Does Tmux supports key-bindings with key sequences like Vim does (e.g. bind-key ab kill-pane)? Or how can i emulate that?
I'm using tmux 2.3.
You can emulate key sequences by defining your own key tables and chaining them together.
For example, if I want <C-q>x to do something, I put the binding for 'x' into a key table "my-keys", then bind the key that activates that key table with switch-client (C-q):
bind-key -Tmy-keys x send-keys "my binding"
# Multi-key prefix for custom bindings
bind-key -Troot C-q switch-client -Tmy-keys
NOTE: I started with C-q, because it seems to conflict the least with the command line and Vim.
So, now you have every key at your disposal with a C-q prefix.
If you want more keys in your sequence, add another level of indirection:
bind-key -Tmy-keys x send-keys "my binding"
# Pane (i.e. 'W'indow commands like Vim with C-w)
bind-key -Tmy-keys-window-ctl s swap-pane
bind-key -Tmy-keys C-w switch-client -T my-keys-window-ctl
# Multi-key prefix for custom bindings
bind-key -Troot C-q switch-client -Tmy-keys
So, now I have swap-pane bound to <C-q><C-w>s.
This works because
<C-q> activates "my-keys" key table,
which has the binding <C-w>,
which activates "my-keys-window-ctl" key table
which has the binding s to call swap-pane
Tmux supports only single character key bindings (unfortunately).
So, only this:
bind-key a kill-pane
or this:
bind-key b kill-pane
Please note this is different from for example C-a (Ctrl-a) or M-a (Alt-a).
Even though we users write those with multiple characters and even have to press 2 keys to invoke them, both Ctrl-a and Alt-a are actually a single character for tmux (and in general to my knowledge).
Alternative
...might not be what you expect, but here it is:
# in .tmux.conf
bind a command-prompt -p "pressed a" "run '~/my_script %%'"
And the example my_script file:
#!/bin/bash
case "$1" in
b)
tmux kill-pane
;;
c)
tmux kill-window
;;
esac
Now after you reload your tmux.conf and press prefix + a you'll get a tmux prompt saying 'pressed a'.
Go ahead and press b and Enter. tmux kill-pane from the script will execute.
Similarly if you press prefix + a + c and Enter you'll execute another option from the script.
This kind-of mimics what you want with the addition of Enter key at the end.
Also, the provided script is extendable so you can add more "bindings" to get prefix + a + d + Enter etc..