Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tmux copy mouse selected text to clipboard automatically on mouse release

Tags:

tmux

I only use mouse text selection in tmux terminal to get the text to clipboard.

Can I configure tmux to put the just selected text into system clipboard automatically after the mouse button is released, so I am then able to paste the text with Ctrl-v in some other application like firefox?

like image 781
mmm Avatar asked Apr 23 '16 20:04

mmm


Video Answer


2 Answers

It turns out that since tmux 2.2 we can bind a command to MouseDragEnd1Pane event.

So this one line in ~/.tmux.conf configures tmux to copy the mouse selected text to the system clipboard automatically after mouse button is released:

bind-key -t vi-copy MouseDragEnd1Pane copy-pipe "xclip -in -selection clipboard"
like image 105
mmm Avatar answered Oct 24 '22 17:10

mmm


I'm using tmux 2.5 in iTerm2 on OSX Sierra, and this works for me:

unbind -T copy-mode MouseDragEnd1Pane
bind-key -T copy-mode-vi MouseDragEnd1Pane send -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"

If you don't want to cancel the selection, you can use copy-pipe instead of copy-pipe-and-cancel.

See also reattach-to-user-namespace on Github.

like image 23
Adam Millerchip Avatar answered Oct 24 '22 16:10

Adam Millerchip