9
votes

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?

2
That's what happens anyway? - pfnuesel
I clarified it a bit what is not working for me. - mmm
There is software that merges the two clipboards. Never used one myself, but maybe you can google for it. - pfnuesel

2 Answers

14
votes

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"
3
votes

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.