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 PRIMARY
selection which uses the mouse selection for copy and pastes with the third button. However this becomes less and less common, so I'll configure the CLIPBOARD
selection most newer browsers, applications and Emacs use.
Add 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 X clipboard contents and paste. The second line sets C-b >
to send current tmux
buffer to X clipboard for pasting to another application.
If you still like to use PRIMARY
selection, you can drop b
options from xsel
, using xsel -o
and xsel -i
respectively.