Linux – tmux freezes when using ctrl-prefix ctrl-y

linuxtmux

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.

Best Answer

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.

Related Question