1

I recently did a fresh Ubuntu 18 install and copied over my home directory from my previous Ubuntu 16 setup. However this seems to have broken the copy paste functionality I had previously with xclip (0.12 installed).

My previous tmux.conf method:

setw -g mode-keys vi
bind -t vi-copy y copy-pipe "xclip -sel clip -i"

I've looked at other similar questions on here but unfortunately none of them match my exact scenario.

3

As of tmux 2.6, bind-key no longer takes a mode-table option (-t). Instead, there is a a key-table (-T) for each mode.

Additionally, commands can't be used directly in copy-mode bindings. They have to be sent with send-keys -X.

From comments on tmux issue 754:

  1. replace -t with -T
  2. replace vi-<name> with <name>-mode-vi
  3. prefix the command with send-keys -X

Furthermore, from version 2.4 onwards, the new command copy-pipe-and-cancel leaves copy mode, while copy-pipe keeps it active.

So that line in your tmux.conf becomes:

bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -sel clip -i"

Garbage printed to the screen

Depending on your terminal emulator, you may also see some characters dumped to the screen after using this binding. This is down to the set-clipboard feature:

Attempt to set the terminal clipboard content using the xterm(1) escape sequence, if there is an Ms entry in the terminfo(5) description (see the TERMINFO EXTENSIONS section).

It appears that some terminals (such as LXTerminal) will set TERM to xterm (which supports this extension), but don't actually recognise the sequence. copy-pipe and copy-pipe-and-cancel will "helpfully" attempt to use this feature, and the terminal simply displays the resulting characters. What you're seeing is the escape sequence followed by the base64-encoding of the selected text.

If your terminal is one that mishandles this escape sequence, you can disable it with

set-option -g set-clipboard off
8
  • Hi, thanks but still no luck. When I select the area pressing 'y' has no affect where it should instead copy the selected area
    – Shardj
    Dec 21 '18 at 16:11
  • Have you restarted all tmux sessions after changing this line? Are there any error messages, either when tmux starts (and reads this line from the config file) or when you use the binding?
    – JigglyNaga
    Dec 21 '18 at 16:15
  • All tmux sessions? No I just tested in a new one. I'll restart all of them and give it another try when I'm back at work on monday. Thanks
    – Shardj
    Dec 22 '18 at 18:15
  • Hi, sorry I've been so long, Christmas holidays and all. It kind of works now, I can copy things, but when I press 'y' as well as copying it also sticks a bunch of characters on the screen, the first is weird utf8 and the rest are ascii but jumbled. I'll make as accepted though since it is usable.
    – Shardj
    Jan 2 '19 at 14:24
  • @Shard Which terminal are you using? I see that exact symptom in LXTerm, but not in any others. I haven't got to the bottom of it yet, although I noticed that the characters are the base64-encoding of the copied text.
    – JigglyNaga
    Jan 2 '19 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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