Copying and pasting with XWindow clipboard from tmux
tmux does not natively support XWindow’s clipboard. With two lines in
.tmux.conf, you can configure two keys to send and retrieve clipboard
content.
Traditionally, applications use the PRIMARY selection, which uses the mouse
selection for copying and pasting with the middle mouse button. However, this
is becoming less common, so I’ll configure the CLIPBOARD
selection used by most modern browsers, applications, and Emacs.
Add the following lines to .tmux.conf:
# move x clipboard into tmux paste buffer
bind < run "xsel -ob | tmux load-buffer - ; tmux paste-buffer "
# move tmux copy buffer into x clipboard
bind > run "( tmux show-buffer | xsel -bi ) && tmux display-message \"ok!\""
The first line sets C-b < in tmux to retrieve the X clipboard contents
and paste them. The second line sets C-b > to send the current tmux buffer to
the X clipboard for pasting into another application.
If you would still like to use the PRIMARY selection, you can drop the b options
from xsel, using xsel -o and xsel -i respectively.