0

I want to copy tmux selection inside system clipboard and found several solutions online. I grabbed this key bind configuration due to simplicity and added to my tmux.conf file.

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"

Both key bindings works but terminal halts after triggering copy command key binding.

Here are my steps to copy selection:

  1. Prefix + [
  2. Press space to mark selection
  3. Select text using arrow keys
  4. Prefix + ctrl + c

At this point, the selection is available in system clipboard (tested it by pasting in other application). But the terminal window is not responding, even tried random keys but have no luck. I closed the terminal from x icon and open new window. The terminal behaves normally after reattaching to previous session in new window.

Most likely, I am doing something wrong but I'm unable to troubleshoot the bug.

Q. How can I troubleshoot and fix this problem?

Alena
  • 103
  • What happens when you highlight text with your mouse in any Tmux pane and then press CTRL+SHIFT+C ? Can you paste the highlighted content somewhere other than in a Tmux pane with CTRL+V, or in another Tmux pane with CTRL+SHIFT+V ? – Cbhihe Sep 20 '21 at 15:40
  • @Cbhihe the CTRL+SHIFT+C shortcut doesn't work. First, the mouse selection disappears as soon as I leave the left click and I have even tried holding the left click but did not worked. However, I found working solution in suggested question. – Alena Sep 21 '21 at 07:09
  • Don't know what your tmux version is, but if just using your mouse to copy paste sounds like a good option to you, check out this answer by GMaster. It applies to MacOS and to Linux platforms. – Cbhihe Sep 21 '21 at 07:54
  • thanks, I would definitely use this! – Alena Sep 21 '21 at 10:34

1 Answers1

2

In the context of a local tmux session, the unresponsiveness you experience is due to xclip taking time to close stdout. See here for a good explanation.

Edit your ~/.tmux.conf to change your first key binding to:

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

(or perhaps bind-key instead of bind) as put forth by PlasmaBinturong here.

Cbhihe
  • 2,701