learntmux.dev

Mouse copying behaviour

Goal

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.

Do this

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.

Stuck on this one?

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

about 15 MB, once

session learn

Done when

not started
  1. The mouse option is on— not done yet
  2. MouseDragEnd1Pane in the copy-mode table runs copy-selection-no-clear— not done yet
  3. A buffer holds the token line, from a mouse drag or a keyboard copy— not done yet