4

In tmux, we use the trigger key Ctrl-b followed by an action key. However, I would like to assign direct keys in my .tmux.conf and was hoping this is possible. I would like to assign F7 (without the need to press Ctrl-b) to start copy mode (i.e. equivalent to Ctrl-b followed by [) and also to allow Esc to act in the same way that q does when in copy mode (i.e. it drops out of copy mode). So, F7 to enter copy mode and Esc to leave copy mode. Is that possible?

4

tmux has several key-binding tables, as documented in man tmux under "bind-key". There are several default tables:

  • The root table is where the prefix key itself is bound.
  • The prefix table is used after the prefix is pressed, and is the one your usual keybindings go.
  • The copy-mode table is used in copy mode if mode-keys is set to "emacs".
  • The copy-mode-vi table is used in copy mode if mode-keys is set to "vi".

If you want to bind without the prefix key, use the -n or -T root option to bind-key.


Esc might behave slightly weird, as the terminal codes for nearly all special keys (Alt+keys, function keys, arrow keys, etc) also begin with exactly the same Esc. Programs like Vim use a timer to distinguish the two. You may need to lower the escape-time parameter in tmux.

4
  • Indeed, I'm having a problem with that. I see that Escape is used in tmux bind-key -T copy-mode Escape send-keys -X cancel and the listing for q is also bind-key -T copy-mode q send-keys -X cancel, so they are the same by default(!), but Escape does not exit copy mode for some reason. I'm just trying to learn tmux for a couple of days, so if you anything you can suggest on implementing escape-time parameter would be great and I will give it a try?
    – YorSubs
    Sep 22 at 17:32
  • "copy-mode" is for emacs; you want the "copy-mode-vi" table instead. (I'm reading the docs for tmux 3.2.) Generally, I have set -g escape-time 50, so that tmux would be faster at forwarding the keypress to Vim.
    – user1686
    Sep 22 at 17:37
  • I just get /home/boss/.tmux.conf:13: unknown command: copy-mode-vi when I try to use this. Sorry, I'm a little confused... what would the command in .tmux.conf be do you think for the Escape key?
    – YorSubs
    Sep 22 at 17:58
  • It's not a command, it's a table name for bind-key.
    – user1686
    Sep 22 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.