I'm running tmux 1.6 and I'm trying to configure it to use vi-style keybindings as well as use the system clipboard when copying in interactive mode:
set-window-option -g mode-keys vi
bind-key -t vi-copy 'v' begin-selection
bind-key -t vi-copy 'y' "copy-selection && run \"tmux save-buffer | xclip -selection clipboard\""
Simply put, I'd like to be able to do C+[ and then use v to begin selecting text for copying, then when y is pushed, copy the selection to the tmux selection and then export it to the system clipboard using xclip
.
Unfortunately, when I try to do this, I see the following:
.tmux.conf: 14: unknown command: copy-selection && run "tmux save-buffer | xclip -selection clipboard"
Is there a way to do this in tmux configuration?
xclip
is actually installed in your system (it's not installed by default on Ubuntu, you need tosudo apt-get install xclip
to get it) – RubenLaguna May 28 '15 at 11:26xclip
withpbcopy
. For Cygwin on Windows, replace it withputclip
(from thecygutils-extra
package). – SnoringFrog Jun 17 '16 at 15:09bind -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xclip -i -f -selection primary | xclip -i -selection clipboard"
– Matthias Braun Nov 30 '17 at 19:30set -g mouse on
. This is supposed to enable "mouse mode" but even after removing it everything regarding my mouse works fine (scroll wheel works, mouse selection works)... – ndemou Jun 15 '18 at 10:32
– Gurce Jan 08 '19 at 03:10bind-key -t vi-copy y copy-pipe "cat >/dev/clipboard"
tmux ls
andtmux kill-session -t [id]
it started working. You can enter tmux command mode by doingprefix + :
and there you can enter thebind -T copy-mode-vi ...
command manually to see if it'll work on a fresh session at all – walnut_salami Jan 11 '20 at 12:07bind
line isn't a terminal command. It belongs in the~/.tmux.conf
file – AjaxLeung Jan 26 '20 at 09:14<Space>
(for starting visual mode/selection) to actualv
button(to stay consistent withvim
style). Or is it simply impossible? – Drew Jan 07 '21 at 12:10xclip
) – axolotl Oct 05 '21 at 14:38cat > ~/.cache/clipboard
as one comment above suggests (but with/dev/clipboard
) – axolotl Oct 05 '21 at 14:39set -s copy-command 'xclip -selection clipboard'
is sufficient. Note this does not bind with Y, you don't need press y after enter. See https://github.com/tmux/tmux/wiki/Clipboard#available-tools – unifreak Jan 13 '23 at 22:46unbind enter
beforebind -T copy-mode-vi enter send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard'
– Wu Wei Jan 27 '23 at 23:34