Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

On mu ubuntu 12.04 setups my tmux clipboard copy and paste commands are setup as follows:

set -g prefix M-a
unbind C-b
bind C-c run "tmux save-buffer - | xclip -i -sel clipboard"
bind C-v run "tmux set-buffer \"$(xclip -o -sel clipboard)\"; tmux paste-buffer"

This worked great for the longest time up until a month or so ago, when I suspect some configuration change or package change was made that broke the above. In GNOME terminal, pasting still works fine with both prefix + C-v and CTRL-SHIFT-v.

However the xclip copy command no longer works no matter what I do, and I have tried removing the custom prefix binding above, using -select instead of -sel, not using "clipboard" etc. This is pretty much a show stopper for a GVim user like me, since I don't even have the GNOME terminal workaround of CTRL-SHIFT-c with tmux taking over the shell. I go into copy mode, select text with SPACE + movement, and when I execute prefix + C-c absolutely nothing happens. Before this broke, tmux would display a confirmation message in the notification section at the bottom.

Does anybody have suggestions as far as how one might debug this? This is a pretty big productivity hit. I can probably use the temporary file workaround trick for now, but it'd be great to know just what happened to xclip.

share|improve this question
Is xclip actually available? What is the output of type xclip? –  Chris Down May 28 '13 at 5:18
The output is: "xclip is /usr/bin/xclip". As I mentioned, pasting through xclip works just fine for whatever reason. –  Alexandr Kurilin May 28 '13 at 5:20
Do you have the same problem with xsel -b? –  Gilles May 29 '13 at 7:34
@Gilles, xsel -i -b does seem to do the trick! –  Alexandr Kurilin May 29 '13 at 20:30
Heh. I have no idea why it works, I thought xsel -b and xclip -selection clipboard would do the same thing! –  Gilles May 29 '13 at 21:45
add comment

4 Answers

up vote 4 down vote accepted

The xsel utility is similar to xclip, but implemented a little differently. Normally I would expect them to behave in the same way, but they don't make exactly the same X library call, so it's possible that in some corner cases xsel will work but not xclip, or vice versa. Try:

bind C-c run "tmux save-buffer - | xsel -ib"
bind C-v run "tmux set-buffer \"$(xsel -ob)\"; tmux paste-buffer"
share|improve this answer
add comment

I'm experiencing a similar problem and the temporary file won't help in this particular case, I'm afraid. This is because xclip seems to behave differently when spawned by tmux than when being run "interactively" and waits for another application to take ownership of the clipboard area. Try using xclip -l 1 to make it quit immediately (see man page for details).

share|improve this answer
Can't seem to get that work work. Is this what that binding should look like: bind C-c run "tmux save-buffer - | xclip -l 1 -i -sel clipboard" ? –  Alexandr Kurilin May 28 '13 at 17:41
Could you perhaps post what workaround worked for you? That'd be pretty helpful as well! –  Alexandr Kurilin May 28 '13 at 17:51
I'm using bind C-y run-shell "tmux save-buffer - | xclip -l 1 -i". –  peterph May 28 '13 at 21:04
Yeah, still nothing unfortunately. Tmux doesn't report anything, nor does xclip. –  Alexandr Kurilin May 29 '13 at 0:17
For me it's not reporting anything either, but it works. Check what xclip is doing when you try to copy the buffer. If it stays hanging there waiting for something, does killing it help? Also, you have to exit the selection mode by hitting Enter (and hence storing it into buffer) before you try to copy the buffer into the X clipboard. –  peterph May 29 '13 at 9:36
show 5 more comments

Adding -b to run-shell (or run) command fixed the problem. With -b the shell command is run in the background.

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

share|improve this answer
add comment

Although I can't reproduce it anymore but here's the technical answer what might have happened in your case.

First, you need to understand how X11 clipboard works. You might read jwz's essay on this: http://www.jwz.org/doc/x-cut-and-paste.html

In short, the application which holds the contents of the clipboard needs to run until other application asserts the ownership. So when you run xclip -i <<< test then you can see xclip running in the background until you make another selection:

$ xclip -i <<< test
$ ps
  PID TTY          TIME CMD
10166 pts/8    00:00:00 xclip
10171 pts/8    00:00:00 ps
19345 pts/8    00:00:00 bash

Now this is all fine but when you exit this shell then all processes belonging to this session are killed by default by sending them a HUP signal. This will mean xclip will be killed and you won't be able access your clipboard contents anymore.

So the suggested workaround (in case you don't have xsel) is to ignore the HUP signal by using the following bind:

bind C-c run "tmux save-buffer - | nohup >/dev/null 2>/dev/null xclip -i -sel clipboard"

xsel is not affected by this problem because the first thing it does after the fork() is to disassociate itself from the controlling terminal so it won't receive the HUP signal when its shell exits (you won't even see it in the above ps output but only when you do a ps -e | grep xsel).

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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