Strovent SystemsSign in
Reference

Can't select or copy text in tmux over SSH: mouse mode, Shift and the clipboard

With tmux mouse mode on, the terminal sends the mouse to tmux instead of selecting. In xterm, hold Shift to select, or copy in tmux to the clipboard.

You turned on mouse support in tmux so you can scroll and click panes. Now dragging over text no longer selects it in your terminal, or it selects something that disappears when you let go. Both are expected with tmux's mouse mode.

Why selection stops working

With set -g mouse on, tmux asks the terminal to report mouse events, and it binds them as keys (the option is off by default). While that mouse reporting is on, your terminal sends clicks and drags to tmux instead of using them to select text on your side. tmux uses the drag to make its own selection in copy mode, which goes into a tmux paste buffer on the host, not into your device's clipboard.

Select with your terminal anyway: Shift in xterm

The xterm manual says xterm normally lets you hold the Shift key to temporarily override the mouse protocol, so its normal selection and copy actions work. Whether another terminal app has an override key, and which key it is, depends on that app; check its documentation.

A selection made this way is a plain screen selection: it does not know about tmux panes, so it can take text from two panes side by side. Zoom the pane first (prefix then z) to select from one pane only.

Copy with tmux, and get it to your clipboard

If you select with tmux instead, the text goes to a tmux buffer. To have tmux also put it on your device's clipboard, tmux uses the xterm clipboard escape sequence (OSC 52). The tmux set-clipboard option controls this: on or external makes tmux try to set the terminal clipboard, if the terminal's terminfo entry declares the capability. It only works if your terminal app accepts OSC 52. This app does not act on OSC 52 copy requests; to copy text in the app, see Copy, paste and select. Over Mosh, see Mosh and OSC sequences: clipboard (OSC 52), titles, hyperlinks, OSC 7 and OSC 133.

Or turn mouse mode off

If you mostly want local selection, turn it off:

tmux set -g mouse off

and remove set -g mouse on from ~/.tmux.conf. Scrolling then uses copy mode with the keyboard; see Scroll back and search history in tmux.

Sources

Spotted a mistake? Email [email protected].