Is there a way to do this in ~/.tmux.conf?
tmux may be controlled from an attached client by using a key combination of a prefix key, 'C-b' (Ctrl-b) by default, followed by a command key. The default command key bindings are: C-b Send the prefix key (C-b) through to the application. C-o Rotate the panes in the current window forwards.
The prefix key is an essential part of tmux, by default all of tmux's key-bindings sit behind a prefix. This prefix is very similar to vim's leader key. It is common for folks to change the default C-b (control b) to C-a or if they are a vim user something to match their vim leader key.
To list all current key bindings, including any custom bindings you've added and bindings added by plugins: Ctrl + b ? tmux list-keys or tmux lsk in a shell inside tmux. list-keys or lsk at tmux's command prompt ( Ctrl + b : )
If everything else is configured correctly, it should be as simple as putting this in your .tmux.conf
:
set-option -g prefix Home
Note: Unless you manually “source” your .tmux.conf
, changes to the file will only take affect when the tmux server is restarted. Either cleanly exit all your panes, windows (thus closing all your sessions and letting the server exit), or use tmux kill-server
, then start a fresh session.
This will only work if your terminal emulator is sending an escape sequence that matches the khome
field of the terminfo database entry for the TERM
value in effect when you connect to your tmux session (i.e. the TERM
“outside of” tmux).
You can verify the escape sequence sent by your terminal emulator by typing the Home key (and a newline) into cat -v
(you can abort cat with Control-C once it shows you the sequence). Common responses might be ^[[1~
or ^[OH
.
The TERM
environment variable tells terminfo-based programs (like tmux) what escape sequences your terminal emulator (supposedly) understands and generates. The escape sequence generated by the Home key is stored in the khome
field. You can use tput or infocmp to extract the field’s value (both use the current TERM
unless they are given an overriding terminal declaration).
tput khome | cat -v ; echo
infocmp -1 | grep -F khome
If the escape sequence generated by your terminal emulator does not match the khome
entry for your declared TERM
value, then there are a several things that can be done to try to fix the problem:
TERM
value that is a better match to what your terminal emulator sends and understands.terminal-overrides
option that can be used to override individual terminfo fields for various TERM
values.For example, if your terminal emulator does not send a sequence for Home, but you can configure one, and the terminfo entry for your TERM
does not have a khome
field, then you could
tell your terminal emulator to send ESC [
1
~
, and use termname:khome=\033[1~
for your terminal-overrides
value (where termname
is a pattern that suitably matches your TERM value).
E.g. in .tmux.conf:
set-option -g terminal-overrides "xterm-color:khome=\033[1~"
You can use tmux server-info
to inspect tmux’s runtime copies of the terminfo entries.
Note: As above (with the prefix
change), the easiest way to let this change become effective is to restart your tmux server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With