Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would I go about binding the HOME key as a tmux prefix?

Tags:

tmux

Is there a way to do this in ~/.tmux.conf?

like image 575
secondplanet Avatar asked Oct 31 '11 20:10

secondplanet


People also ask

How do you bind keys in tmux?

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.

What is the tmux prefix key?

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.

Where is bind key tmux?

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 : )


1 Answers

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).

Generated Escape Sequence for Home

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.

Expected Escape Sequence for Home

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

Fixing a Generated/Expected Mismatch

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:

  1. Reconfigure your terminal emulator.
    This may involve using a different program, picking a different emulation, or just (re)defining the sequence it sends when you press the Home key.
  2. Pick a new TERM value that is a better match to what your terminal emulator sends and understands.
  3. Adjust a terminfo database entry to match your terminal emulation.
    You can use infocmp to extract and existing terminfo entry and tic to compile your modified entry.
  4. Tell tmux to adjust its runtime copies of the terminfo database entries.
    tmux provides the 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.

like image 140
Chris Johnsen Avatar answered Oct 21 '22 04:10

Chris Johnsen