In order to copy text to X clipboard in tmux, what I currently do is:
- go selection mode with prefix[
- start selection with space (using
mode-keys vi
btw) - select the text and press enter
- copy tmux buffer to X clipboard using prefixctrl+c
(I have a mapping as bind C-c run "tmux show-buffer | xclip -selection clipboard -i"
I'm trying to eliminate some of these steps by making a mapping for selection mode. I have tried:
bind-key -t vi-copy C-c run "tmux show-buffer | xclip -selection clipboard -i"
which gives me and error:
.. usage: bind-key [-cnr] [-t key-table] key command [arguments]
(I couldn't copy the error)
how can I fix this?
EDIT: I have realized I can select and copy to tmux buffer (first 3 steps) using mouse just like a regular selection (although highlighting doesn't last, it still selects the text) and then use the following bind to copy to x clipboard:
bind-key -n C-c run "tmux show-buffer | xclip -selection clipboard -i"
(I used this method to copy this text and it was easy ;)
note that -n
denotes "no prefix" therefore no escaping is needed. if you don't get confused by the vanishing highlight this is analogous to regular (common user interface) copying.
this is the best I have come up with so far..
EDIT2: turned out ctrl+c overlaps with process interrupt thing so I changed to ctrl+alt+c for now. (didn't quite like it)
EDIT3: tmux 1.8 or so added support to add keybindings in copy mode so now my first original intention is possible using something like:
bind-key -tvi-copy y copy-pipe "xclip -selection clipboard -i"
bind-key -tvi-copy enter copy-pipe "xclip -selection clipboard -i"
These two bindings make it possible to copy text to clipboard when I used enter or y to finish copying.
I still keep this line in case I do the copying with mouse and decide to get the tmux buffer content to clipboard later on:
bind-key y run "tmux show-buffer | xclip -selection clipboard -i"
stty intr=^Z
. Be careful with that command, it's possible to set a regular character to be the interrupt character (if you do so, use ctrl-v to enter it until fixing the setting). And don't get confused on what key is used (e.g. ctrl-z is normally the suspend key). – ash Sep 05 '13 at 06:20^c
as the interrupt key as I use it more often than copying. I have also updated the answer to reflect my current solution to this problem. – none Sep 05 '13 at 10:22bind-key -t vi-copy C-c run "tmux show-buffer | xclip -selection clipboard -i"
live gives:Unknown command: run
– Alexej Magura Dec 24 '13 at 17:14bind-key C-c run "tmux show-buffer | xclip -selection clipboard -i"
works just fine. – Alexej Magura Dec 24 '13 at 17:20cat |
in the last version of your commands for? They shouldn't be needed and look odd to me. – xaizek Jan 09 '14 at 20:10&>/dev/null
to the ran command. – Chuim Jan 12 '15 at 10:39