Mouse copying behaviour
Mouse on, MouseDragEnd1Pane copies without clearing, and the token line is in a buffer.
A mouse drag ends with MouseDragEnd1Pane — a key like any other, which means you can rebind what a drag does:
copy-pipe-and-cancel- the default: copy, then leave copy mode
copy-selection-no-clear- copy, but keep the selection and stay in copy mode
- unbound
- the drag only highlights; copying is left to the keyboard
Because mouse events are ordinary bindings, bind, unbind and list-keys all work on them. The binding goes in the copy-mode table: by the time the drag ends, the pane is already in copy mode.
Press C-b :, type set -g mouse on, Enter.
Without this, a drag selects in your terminal rather than in tmux.
Press C-b :, type list-keys -T copy-mode MouseDragEnd1Pane, Enter.
It shows the default, copy-pipe-and-cancel.
Press C-b :, type bind -T copy-mode MouseDragEnd1Pane send -X copy-selection-no-clear, Enter.
The drag now has new behaviour.
Drag across the token: line and release.
The line stays highlighted, the pane stays in copy mode, and a buffer holds it.
The copy-mode key table
copy-mode is the right table here because this server uses emacs keys. With mode-keys vi set, the same binding would belong in copy-mode-vi.
Here is what just happened.
bind -T copy-mode wrote into the copy mode table with a mouse event as the key. The new command is a copy mode command sent with -X, like every other; it does the copy but skips the -cancel step the default performs.
- Copy on release but keep the selection highlighted and stay in copy mode:bind -Tcopy-mode MouseDragEnd1Pane send -X copy-selection-no-clear
- Do nothing on release; copy with the keyboard instead:unbind -Tcopy-mode MouseDragEnd1Pane
Go further
copy-selectioncopies and clears the highlight but stays in copy mode: a middle ground.MouseDown1Pane,MouseDrag1Paneand the status line and border events are listed under “Mouse key bindings” inman tmux.- Put the working binding in
~/.tmux.confso it survives a restart.
- 1Turn the mouse on first with
:set -g mouse on; without it a drag selects in your terminal, not in tmux. - 2The binding is in the
copy-modetable::bind -T copy-mode MouseDragEnd1Pane send -X copy-selection-no-clear. - 3Then drag across the
token:line and release. No mouse events?C-b [,C-Space,C-e,M-wfills the buffer just as well.
This is a live terminal. Typing goes to the machine, including Tab. Press Shift and Tab together to move focus back out to the page.
A real terminal, in this tab
Alpine Linux and tmux 3.4 on an x86 emulator. Nothing to install, and no server behind it.
about 15 MB, once
Done when
not started- The mouse option is on— not done yet
- MouseDragEnd1Pane in the copy-mode table runs copy-selection-no-clear— not done yet
- A buffer holds the token line, from a mouse drag or a keyboard copy— not done yet