6

I'm using a custom .tmux.conf file which looks like this:

unbind-key C-b
set -g prefix C-a
bind-key C-a send-prefix

set-window-option -g mode-keys vi
bind-key -t vi-copy 'v' begin-selection
bind-key -t vi-copy 'y' copy-selection

## CLIPBOARD selection integration
# Requires prefix key before the command key
# Copy tmux paste buffer to CLIPBOARD
bind C-y run "tmux show-buffer | xclip -i -selection clipboard"
# Copy CLIPBOARD to tmux paste buffer and paste tmux paste buffer
bind C-p run "tmux set-buffer -- \"$(xclip -o -selection clipboard)\"; tmux paste-buffer"

I'm using ctrl+a ctrl+y to copy from tmux copy buffer to clipboard. But every time I do this tmux freezes and does not accept any input. I tried to use ctrl+q but this doesn't help.

What can I do to prevent tmux from freezing, which shortcuts are interfering here? I also tried the shortcut ctrl+a ctrl+c, same problem here.

1
  • please consider adding that to your question so it looks nice.
    – Ashildr
    Oct 3, 2013 at 13:29

3 Answers 3

8

If you type the xclip command on the command line you'll notice that it doesn't finish. This is because it continues to accept input until STDIN is done. Thus, STDOUT never gets closed. You can resolve this by redirecting the STDOUT of xclip to /dev/null. For example:

bind y run "tmux save-buffer - | xclip -selection clipboard &>/dev/null"

In this example I redirect STDERR as well just in case it matters.

4
  • This is a very enlightening answer, but it does not solve the problem. For example, ps aux | grep xclip shows that the xclip process is still running, and continues to block the tmux terminal. Any suggestions for a command, like the one shown above, that also kills the xclip process?
    – modulitos
    Nov 18, 2014 at 5:36
  • Since I stumbled here, I thought I'd note that that is just how the xclip works. It stays running even when run from command line. The -b is the right thing to do here, otherwise tmux will attempt to wait it out, which it shouldn't do with xclip. Sep 21, 2021 at 6:07
  • @TommiKyntola not all xclip versions have -b
    – Conner
    Sep 21, 2021 at 11:49
  • @Conner Hardly any of them do afaik, the -b is an option to the tmux run-shell command. Oct 14, 2021 at 20:03
3

xclip is waiting for input, which blocks tmux from receiving input. The following example allows xclip to run in another shell without blocking your tmux session:

bind y run-shell -b "tmux save-buffer - | xclip -selection clipboard"

I would even add a message to help your workflow:

bind y run-shell -b "tmux save-buffer - | xclip -selection clipboard; tmux display-message \"Tmux buffer saved to clipboard\" "

I hope this helps!

0
bind y run-shell -b "cat << EOF | tmux save-buffer - | xclip -sel clipboard &>/dev/null"

you can do it this way the EOF closes the buffer after copying it to clipboard with xclip.

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Sep 27, 2022 at 8:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .