Working with the Clipboard on Linux

Using the xclip utility,[12] you can integrate your buffers with the Linux system clipboard so you can more easily copy and paste between programs.

First, you have to install xclip. On Ubuntu, use this command:

 
$ ​sudo apt-get install xclip

Then we use tmux’s save-buffer and set-buffer commands with xclip.

To copy the current buffer to the system clipboard, we add this command to our .tmux.conf file:

 
bind​ C-c run ​"tmux save-buffer - | xclip -i -sel clipboard"

This configures Prefix Ctrl-c so it captures the current buffer and pipes its output to xclip. We then add this line to our configuration so we can use Prefix Ctrl-v to paste text from the system clipboard into a tmux session:

 
bind​ C-v ...

Get tmux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.