Tmux:如何将功能键绑定到命令?

Tmux: how do I bind function keys to commands?

如何将功能键(例如 F1,生成 ESC O P)绑定到 tmux 命令(例如 "next window"、ctrl-B n)?

上下文:mac 上的 ssh 运行 进入 linux 上的 tmux 会话。我在 mac 键盘上按 fn-F1 以生成 ESC O P.

来自 man tmuxKEY BINDINGS 部分:

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.

因此, bind-key -n F1 next-window 将允许您在 macbook 上点击 fn-F1 以切换到 tmux 会话中的下一个 window。