secondplanet
secondplanet

Reputation: 115

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

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

Upvotes: 6

Views: 2223

Answers (1)

Chris Johnsen
Chris Johnsen

Reputation: 224591

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.

Upvotes: 16

Related Questions