104

I'm using tmux 2.1 and tried to on mouse mode with

set -g mouse on

And it works fine, I can switch across tmux window splits by clicking the appropriate window. But the downside of this is that I cannot select text with mouse. Here is how it looks like:

enter image description here

As you can see, the selection just become red when I keep pressing the mouse button and disappear when I release the button. Without mouse mode enabled the "selection with mouse" works completely fine.

Is there some workaround to turn mouse mode on and have the ability to select text?

4 Answers 4

183

If you press Shift while doing things with the mouse, that overrides the mouse protocol and lets you select/paste. It's documented in the xterm manual for instance, and most terminal emulators copy that behavior.

Notes for OS X: In iTerm, use Option instead of Shift.  In Terminal.app, use Fn.

9
  • 17
    Note: On iTerm for MacOS use option instead of shift
    – KNejad
    Commented Feb 16, 2018 at 13:00
  • 11
    @BastianGruber From the comments section of this SO answer I found that on Terminal.app you should use the FN key
    – KNejad
    Commented Feb 21, 2018 at 13:51
  • 9
    This approach doesn't work well if you have multiple tmux panes. I can select the text, but the selection overlaps terminal lines across all the tmux panes.
    – Eddy R.
    Commented May 17, 2018 at 23:09
  • 7
    @EddyR. This is where ctrl-b + z comes in handy.
    – cfz42
    Commented Oct 27, 2018 at 21:14
  • 3
    All of this "on $foo terminal emulator and $bar OS version, use $baz key" are really holding tools like vim and tmux back. Why is this an ongoing problem?
    – weberc2
    Commented Oct 31, 2019 at 18:38
23

Thomas Dickey's answer is probably what most people are looking for.

To give some more context on the behavior you are observing, when tmux's mouse mode is on it enables text selection within a particular pane. That's the red text highlighting shown in your screenshot. It can be useful when you have split panes and want to only copy text within one.

When you release the mouse button the selected text is copied to tmux's internal clipboard. You can then paste that text using Ctrl+B ].

Unfortunately it does not copy to the system's primary clipboard, so you can't select in tmux and then paste into a browser for instance. You can configure that behavior though. See this answer to How to copy and paste with a mouse with tmux.

1
  • 1
    "clipboard" and "primary" are two types of selection Commented Jun 14, 2019 at 23:11
3

I had a similar issue where mouse click and drag (tmux-yank) stopped working on MacOS, try Cmd+R

2
  • 1
    it appears to work, but curious what does Cmd+R do?
    – zyxue
    Commented May 9, 2022 at 18:10
  • This tip is for Terminal.app - according to the associated item in the "View" menu, Cmd+R toggles "Allow Mouse Reporting".
    – qzyphus
    Commented Jul 31, 2022 at 1:08
1

The following solution works on tmux 3.3a (may work on slightly older version).

# Mouse mode
set-option -g mouse on

bind-key    -T root         MouseDrag1Pane       if-shell -F "#{||:#{pane_in_mode},#{mouse_any_flag}}" { send-keys -M } { copy-mode -M }
bind-key    -T root         WheelUpPane          if-shell -F "#{||:#{pane_in_mode},#{mouse_any_flag}}" { send-keys -M } { copy-mode -e }
bind-key    -T copy-mode    WheelUpPane          select-pane \; send-keys -X -N 5 scroll-up
bind-key    -T copy-mode    WheelDownPane        select-pane \; send-keys -X -N 5 scroll-down

bind-key    -T copy-mode    MouseDrag1Pane       select-pane \; send-keys -X begin-selection
bind-key    -T copy-mode    MouseDragEnd1Pane    send-keys -X stop-selection
bind-key    -T copy-mode    MouseDown1Pane    send-keys -X clear-selection

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .