I am running tmux inside gnome terminal and have been trying to use a binding to copy the contents of tmux's paste buffer to my Linux X clipboard. A lot of places on the internet recommend this:

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

This command works perfectly from the command line:

tmux save-buffer - | xclip -i -sel clipboard

If I bind the shell command to a key and use it from inside tmux (using bind C-c run "tmux save-buffer - | xclip -i -sel clipboard"), it does copy the tmux save-buffer to my clipboard; once I have copied some text in tmux's "copy" mode, using this binding will load the text into my X clipboard, ready to be pasted into a browser or anywhere else. However, it _also_ causes the prefix key to stop working for that terminal.
If I kill the terminal with tmux running inside it and open another terminal and re-attach to tmux, the prefix key will continue working in another terminal.
I also tried the following approach:

Set up an executable file: /usr/local/bin/tmux_to_clip with the command in it

% cat /usr/local/bin/tmux_to_clip 

tmux save-buffer - | xclip -i -sel clipboard

and then call the command from inside tmux

:run tmux_to_clip

again, it successfully copies the command to the clipboard, but again it breaks the prefix key. How can I prevent this and get a keybinding for copying tmux save-buffer to the X clipboard?

  • I believe this is caused by the way in which xclip forks, although that is just a hunch for trying out as many combinations of run-shell that I can (with pipes, without pipes, using other programs, etc). – magnus Feb 7 '17 at 1:27

I was experiencing the same (annoying) problem. It seems that using xsel -ib instead of xclip -i -sel clipboard, as suggested in this answer, works!

So the final binding should be: bind C-y run "tmux save-buffer - | xsel -ib"

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.