Reputation: 7255
I am learning to use tmux, I found when I in a tmux window, double-click to select and copy function did not work any more.
Can I use double-click to select and copy just as in iterm2?
I have googled for some time, but did not find an short and clear answer to this. I have added setw -g mode-mouse on
in the tmux configure file already.
Upvotes: 40
Views: 17195
Reputation: 47968
Don't know about iterm2, but this can be made to work in tmux 3.0 or newer
(tested on Linux w/ tmux 3.0, last command uses wl-copy on Wayland, otherwise X11 xclip).
Added triple click to select and copy a line too.
%if "#{==:#{XDG_SESSION_TYPE},wayland}"
# Double LMB Select & Copy (Word)
bind-key -T copy-mode-vi DoubleClick1Pane \
select-pane \; \
send-keys -X select-word \; \
send-keys -X copy-pipe-no-clear "wl-copy"
bind-key -n DoubleClick1Pane \
select-pane \; \
copy-mode -M \; \
send-keys -X select-word \; \
send-keys -X copy-pipe-no-clear "wl-copy"
# Triple LMB: Select & Copy (Line)
bind-key -T copy-mode-vi TripleClick1Pane \
select-pane \; \
send-keys -X select-line \; \
send-keys -X copy-pipe-no-clear "wl-copy"
bind-key -n TripleClick1Pane \
select-pane \; \
copy-mode -M \; \
send-keys -X select-line \; \
send-keys -X copy-pipe-no-clear "wl-copy"
%else
# Assume X11.
# Double LMB Select & Copy (Word)
bind-key -T copy-mode-vi DoubleClick1Pane \
select-pane \; \
send-keys -X select-word \; \
send-keys -X copy-pipe-no-clear "xclip -in -sel primary"
bind-key -n DoubleClick1Pane \
select-pane \; \
copy-mode -M \; \
send-keys -X select-word \; \
send-keys -X copy-pipe-no-clear "xclip -in -sel primary"
# Triple LMB: Select & Copy (Line)
bind-key -T copy-mode-vi TripleClick1Pane \
select-pane \; \
send-keys -X select-line \; \
send-keys -X copy-pipe-no-clear "xclip -in -sel primary"
bind-key -n TripleClick1Pane \
select-pane \; \
copy-mode -M \; \
send-keys -X select-line \; \
send-keys -X copy-pipe-no-clear "xclip -in -sel primary"
%endif
If you don't use copy-mode-vi
, replace this with copy-mode
.
If you don't want to copy the word without staying in copy mode you can add the following lines to the command.
run "sleep 0.15" \; \
send-keys -X cancel
So the full command reads:
bind-key -n DoubleClick1Pane \
select-pane \; \
copy-mode -M \; \
send-keys -X select-word \; \
send-keys -X copy-pipe-no-clear "wl-copy" \; \
run "sleep 0.15" \; \
send-keys -X cancel
The sleep is only added so the selected word highlights for a short time, so you know what was copied.
For older tmux versions check the edit-history.
Upvotes: 46
Reputation: 21
This is using tmux 3.3 and pbcopy for macOS Ventula. this works for me.
# Double LMB Select & Copy (Word)
bind-key -T root DoubleClick1Pane select-pane \; copy-mode \; send-keys -MX select-word \; run-shel\
l "sleep 0.1" \; send-keys -X copy-pipe-and-cancel "pbcopy"
# Triple LMB Select & Copy (Line)
bind-key -T root TripleClick1Pane select-pane \; copy-mode \; send-keys -MX select-line \; run-shel\
l "sleep 0.1" \; send-keys -X copy-pipe-and-cancel "pbcopy"
Upvotes: 2
Reputation: 117
Just uncheck the "Enable mouse reporting" option in iTerm2.
But this has side effect: set -g mouse on
in ~/.tmux.conf
will not work.
Upvotes: -2
Reputation: 460
On Kitty/Alacritty, we double-click on the text-block while keeping Shift
pressed. And copying works fine natively as well as within tmux.
Upvotes: 2
Reputation: 311
I have figured out a copy paste mechanism that is similar of what you will expect form a terminal
I used the following settings to be able to:
This solution will keep the selection highlighted and copy the selection output to both clipboard buffers (primary and clipboard)
When you hit "Enter" you exit and go back to the shell
The advantage here is that you can use both middle mouse button as shift-insert combination outside of tmux to paste the content, while it is still selected.
Also when you exited back to the shell, you can use middle mouse button or hit shift-insert to paste the content
All what you would expect from a normal terminal environment
# Enable mouse control
setw -g mouse on
unbind -T copy-mode-vi Enter
bind-key -T copy-mode-vi Enter \
send -X cancel
# Drag and Drop Aelect & Copy (Selection)
bind-key -T copy-mode-vi MouseDragEnd1Pane \
send-keys -X copy-pipe "xclip -in -f | xclip -in -sel c" \; \
send-keys -X no-clear
# Double LMB Select & Copy (Word)
bind-key -T copy-mode-vi DoubleClick1Pane \
select-pane \; \
send-keys -X select-word \; \
send-keys -X copy-pipe "xclip -in -f | xclip -in -sel c" \; \
send-keys -X no-clear
bind-key -n DoubleClick1Pane \
select-pane \; \
copy-mode -M \; \
send-keys -X select-word \; \
send-keys -X copy-pipe "xclip -in -f | xclip -in -sel c" \; \
send-keys -X no-clear
# Triple LMB Select & Copy (Line)
bind-key -T copy-mode-vi TripleClick1Pane \
select-pane \; \
send-keys -X select-line \; \
send-keys -X copy-pipe "xclip -in -f | xclip -in -sel c" \; \
send-keys -X no-clear
bind-key -n TripleClick1Pane \
select-pane \; \
copy-mode -M \; \
send-keys -X select-line \; \
send-keys -X copy-pipe "xclip -in -f | xclip -in -sel c" \; \
send-keys -X no-clear
# Middle click to paste from the primary buffer
unbind-key MouseDown2Pane
bind-key -n MouseDown2Pane run "tmux set-buffer \"$(xclip -o)\"; tmux paste-buffer"
# Shift insert to paste from the clipboard
unbind-key S-IC
bind-key S-IC run "tmux set-buffer \"$(xclip -o -sel c)\"; tmux paste-buffer"
Upvotes: 4
Reputation: 69
Building off of @ideasman42 's answer. This is using tmux 2.8 and pbcopy for macos mojave.
# Double LMB Select & Copy (Word)
bind-key -n DoubleClick1Pane \
select-pane \; \
copy-mode -M \; \
send-keys -X select-word \; \
run-shell "sleep .5s" \; \
send-keys -X copy-pipe-and-cancel "pbcopy"
bind-key -n DoubleClick1Pane \
select-pane \; \
copy-mode -M \; \
send-keys -X select-word \; \
run-shell "sleep .5s" \;
send-keys -X copy-pipe-and-cancel "pbcopy
My version selects the word, briefly highlights it, copies it to the system buffer and then cancels copy-mode.
Upvotes: 5
Reputation: 2429
In Alacrity
holding Shift
allows copying as if there's no tmux.
Upvotes: 15
Reputation: 7255
I found a way to achieve that: hold the option
key when double clicking.
Upvotes: 71