Last Updated: February 25, 2016
·
26.7K
· akalyaev

How to Copy and Paste with Tmux on Ubuntu

1. Install xclip

$ sudo apt-get install xclip

2. Configure Tmux

Open up your Tmux configuration (typically at ~/.tmux.conf) and append:

tmux version >= 1.8

bind -t vi-copy y copy-pipe "xclip -sel clip -i"

Now when you copy some text, it will automatically be copied to OS clipboard.

tmux version < 1.8

# copy & paste between tmux and x clipboard
bind C-p run-shell "tmux set-buffer \"$(xclip -o)\"; tmux paste-buffer"
bind C-y run-shell "tmux show-buffer | xclip -sel clip -i"

Now, when you press <Control> Ctrl-p, it will put the content of x clipboard into Tmux buffer and paste it.

<Control> Ctrl-y will put Tmux top buffer content into x clipboard. Thus, a typical workflow will be as follows:

  1. Enter copy mode
  2. Select text
  3. Yank it
  4. Send it to x clipboard if needed

P.S. Don't forget to restart your tmux server.

2 Responses
Add your response

Nice. The most irritating thing in tmux solved! Thx

over 1 year ago ·

This didn't quite work for me. It was waiting for an EOF in the command and never completed. I eventually used:

bind -t vi-copy y copy-pipe "xclip"

Source: http://unix.stackexchange.com/questions/15715/getting-tmux-to-copy-a-buffer-to-the-clipboard/16405

over 1 year ago ·