Reputation: 15105
It seems that mouse support changed in one of the recent versions of tmux and every article I am finding on the subject uses outdated settings. All I want to be able to do is use my mouse to scroll when in scroll mode and use it to copy/paste with the left button like it usually does in a terminal. Unfortunately, if I set set -g mouse on
the copy/paste doesn't work and if I set it to off, scroll doesn't work. I am on OSX 10.12 Sierra if that makes a difference and I am using the default Terminal app.
Upvotes: 10
Views: 12246
Reputation: 394
I've tried many different solutions but the only working (scrolling with mouse and possibility to copy/paste using usual CMD+C/V
) for me was the one stated over here:
i.e. put this inside ~/.tmux.conf
:
# macOS only
set -g mouse on
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"
bind -n WheelDownPane select-pane -t= \; send-keys -M
bind -n C-WheelUpPane select-pane -t= \; copy-mode -e \; send-keys -M
bind -T copy-mode-vi C-WheelUpPane send-keys -X halfpage-up
bind -T copy-mode-vi C-WheelDownPane send-keys -X halfpage-down
bind -T copy-mode-emacs C-WheelUpPane send-keys -X halfpage-up
bind -T copy-mode-emacs C-WheelDownPane send-keys -X halfpage-down
# To copy, left click and drag to highlight text in yellow,
# once you release left click yellow text will disappear and will automatically be available in clibboard
# # Use vim keybindings in copy mode
setw -g mode-keys vi
# Update default binding of `Enter` to also use copy-pipe
unbind -T copy-mode-vi Enter
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "pbcopy"
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "pbcopy"
then run tmux command source-file ~/.tmux.conf
(by typing CTRL+B
, followed by :
)
Upvotes: 1
Reputation: 11
On OSX and tmux 3.0a
with set -g mouse on
in your tmux.conf
, you can use ctrl-b [
then a mouse drag to select text. After which you should be able to paste with ctrl-b ]
.
Upvotes: 0
Reputation: 5531
One quick way to get copy-paste functionality back using the mouse is to disable "Mouse Reporting"; see the menu item View > Allow Mouse Reporting
in Terminal.app. The default keyboard shortcut is ⌘ Command+r, so a possible workflow is:
Alternatively, hold down the fn key to temporarily obtain the same functionality, as noted in the answer from @yaroslavpalamar.
The comments pointed to an issue with this solution when using multiple panes. This requires a fix from within tmux, in order to simultaneously zoom the pane and allow copy/paste with the mouse. To do that, we can augment the solution pointed to by @MadWombat by adding the line below to the config.
In your ~/.tmux.conf
file (or /etc/tmux.conf
):
bind-key m set mouse \; resize-pane -Z
Then prefix+m is a toggle: hit it once to zoom the pane and allow copy/paste with the mouse, hit it again regain the former functionality. Note this works fine with a single pane as well -- the zoom part of the command has no effect in that case.
Upvotes: 17
Reputation: 418
In my case fn button + mouse works fine for text selection. After selection need to press cmd+c for copying and paste with cmd+v.
Upvotes: 10
Reputation: 445
Using the set -g mouse on
as specified above works to use the mouse for scrolling.
On Linux the shift button works to allow the normal mouse selection and copy/paste, but on Mac it seems to be the Alt button, give that a try (it works for me using tmux on iTerm2).
Upvotes: 0
Reputation: 6476
tmux changed mouse behaviour moving from v2.0 to v2.1.
You can find more information reading tmux's github repository issue 145 description.
I don't use this anymore, but this fixed mouse handling for me after moving to v2.1:
# Handling mouse
set -g mouse on
# Fix Mouse Scrolling: https://github.com/tmux/tmux/issues/145
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"
bind -n WheelDownPane select-pane -t= \; send-keys -M
With this settings you can select using the mouse and the Option (alt) key and then use Cmd-C to copy the selection.
Upvotes: 5
Reputation: 15390
You can hold shift
when selecting text this way it won't invoke copy and paste mode.
https://awhan.wordpress.com/2012/04/18/tmux-copy-paste-with-mouse/
you will notice that you are not able to select text at all. The solution is to use the shift key. Hold down the shift key and then left click and drag across the target text. If you want to now paste the selected text back in to xterm, you must also hold down the shift key and then middle click in order to paste the text. This is not mentioned in the tmux man pages so i do not think this is a tmux feature. guess this has something to do with xterm, but i m not sure.
https://superuser.com/questions/300060/tmux-and-text-selection-with-mouse-through-putty
Upvotes: 0