tmux and clipboard

So you now have started to use tmux as a work tool. The next step you probably you will have a problem a with is clipboard integration.

Tmux has its own cut and paste buffet that you can use within tmux, and as long as you are within tmux you can cut and paste between different screens.

As we have turned on mouse-mode you can even use the mouse to mark and cut stuff. Mouse mode is turned on by setting the followoing lines in the .tmux.conf file.

# Set Scroll on
set -g mode-mouse on

And the keyboard command you are using is:

  • Copy – [ctrl]+a + [
  • Paste – [ctrl]+a + ]

x-clipboard

So now you can cut and paste between the tmux screens, but if you are using tmux from an xterminal windows, as I usually is doing, then you probably also would like to copy thing to and from the x-clipboard.

And yes – you can do that to with tmux. We will use the xsel command. Add the following lines the the .tmux.conf file:

# copy tmux's selection buffer into the X clipboard selection with PREFIX+CTRL+Y
bind-key c-y run "tmux show-buffer | xsel -b -i"
# copy X clipboard selection into tmux's selection buffer with PREFIX+CTRL+P
bind-key c-p run "xsel -b -o | tmux load-buffer -"

 

So now you can use [ctrl]+a + [ctrl]+y to copy your tmux selection buffert into the X clipboard (Yank). And [ctrl]+a + [ctrl]+p to paste from the X clipboard back to the tmux selection buffert (and then use [ctrl]+a + ] to past it back).

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.