Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 it seems only the key binding prefix+q exists for this function; i.e., I can't find the associated :command-style command.

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

like image 729
Luke Davis Avatar asked May 12 '18 23:05

Luke Davis


People also ask

What key do we press to exit copy mode '? Tmux?

To get out of Copy mode, we just press the ENTER key. Moving around one character at a time isn't very efficient. Since we enabled vi mode, we can also use some other visible shortcuts to move around the buffer. For example, we can use "w" to jump to the next word and "b" to jump back one word.

How do I get out of Tmux copy mode?

The solution is to use tmux specific controls to access its own scrollback buffer: Ctrl-b then [ to enter copy mode, use Down/Up arrows or PageDown and PageUp keys, q or Enter to exit copy mode.


1 Answers

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.

like image 170
chepner Avatar answered Sep 24 '22 21:09

chepner