How do I bind a function key (e.g. F1, which generates ESC O P
) to a tmux command (e.g. "next window", ctrl-B n
)?
Context: ssh running on mac into tmux session on linux. I'm pressing fn-F1
on the mac keyboard to generate the ESC O P
.
How do I bind a function key (e.g. F1, which generates ESC O P
) to a tmux command (e.g. "next window", ctrl-B n
)?
Context: ssh running on mac into tmux session on linux. I'm pressing fn-F1
on the mac keyboard to generate the ESC O P
.
From the KEY BINDINGS
section of man tmux
:
tmux allows a command to be bound to most keys, with or without a prefix key. 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 F12, Home, IC (Insert), NPage/PageDown/PgDn, PPage/PageUp/PgUp, Space, and Tab.
bind-key [-cnr] [-t mode-table] [-T key-table] key command [arguments] (alias: bind)
Bind key key to command. Keys are bound in a key table. By default (without -T), the key is bound in the prefix key table. This table is used for keys pressed after the prefix key (for example, by default ‘c’ is bound to new-window in the prefix table, so ‘C-b c’ creates a new window). The root table is used for keys pressed without the prefix key: binding ‘c’ to new-window in the root table (not recommended) means a plain ‘c’ will create a new window. -n is an alias for -T root. Keys may also be bound in custom key tables and the switch-client -T command used to switch to them from a key binding. The -r flag indicates this key may repeat, see the repeat-time option.
Therefore,
bind-key -n F1 next-window
would allow you to hit fn-F1
on your macbook to switch to the next window in your tmux session.