I'd like to copy into and paste from the system (X11) clipboard when making a selection in Tmux and I'd like to bind these actions to the mouse; left click for copy and middle click for paste.
Linux – How to copy / paste from the system clipboard in Tmux in xterm on Linux
linux
Best Answer
For older versions of Tmux (<1.5) or other systems, try
tmux-yank
. For this specific case, however, Tmux very nicely integrates with the system.In your
~/.tmux.conf
, add:to enable mouse support, copying to the system clipboard, and bind a middle-click on a pane to paste.
And in your
~/.Xresources
:to let Xterm select to the system clipboard as well, and allow Tmux to modify the clipboard (a "window operation").
Then, to apply the changes to your
~/.Xresources
, runxrdb -merge ~/.Xresources
and restart Xterm and Tmux.To support macOS and Windows Subsystem for Linux (WSL), we can add
to the
~/.tmux.conf
, and then create~/.tmux.conf.sh
with the following contents:Note that other “advanced” configuration choices can be made in
.tmux.conf.sh
, such as setting configuration values based on the current hostname, distribution, and so on; usingif-shell
is also an option, but is generally pretty clumsy in practice, so using a shell script is an accepted solution.Also note the weird syntax
"${bind_copy[@]}"
, which inserts the$bind_copy
array without performing glob expansion.