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 jus
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.
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 X11 xclip).
Added triple click to select and copy a line too.
# Double LMB Select & Copy (Word)
bind-key -T copy-mode-vi DoubleClick1Pane \
select-pane \; \
send-keys -X select-word-no-clear \; \
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"
If you don't use copy-mode-vi
, replace this with copy-mode
.
For older tmux versions check the edit-history.
In Alacrity
holding Shift
allows copying as if there's no tmux.
source
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"
On Kitty/Alacritty, we double-click on the text-block while keeping Shift
pressed. And copying works fine natively as well as within tmux.
I found a way to achieve that: hold the option
key when double clicking.