Search code examples
keyboard-shortcutstmux

How can I bind a key to "exit copy-mode" in tmux?


I was trying to find a command for "leaving copy-mode" from this page, but I can't find a tux :command that does this -- I can only find the key binding prefix+q.

Does this mean it is impossible to bind another key to "leave copy-mode"? I'd like to bind the Esc key.


Solution

  • Copy mode uses its own set of commands, separate from tmux itself. Use send-keys -X to "type" commands in copy mode, as demonstrated by the default binding for exiting copy mode:

    bind-key    -T copy-mode    q                 send-keys -X cancel
    

    Note that Escape is already bound to the same command, at least in tmux 2.7.

    % tmux list-keys | grep "send-keys -X cancel"
    bind-key    -T copy-mode    C-c               send-keys -X cancel
    bind-key    -T copy-mode    Escape            send-keys -X cancel
    bind-key    -T copy-mode    q                 send-keys -X cancel
    bind-key    -T copy-mode-vi C-c               send-keys -X cancel
    bind-key    -T copy-mode-vi q                 send-keys -X cancel
    

    The page you were referring to is not a comprehensive list of tmux commands, but rather a comparison of how to accomplish some common tasks in different terminal multiplexers.