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?
Best Answer
This was also answered here, but it took me a while to understand how to use it, so I'll explain for anyone else that was confused.
This is basically the setting you're going for:
(for tmux versions <2.5)
(for tmux versions >=2.5)
Then hit
Ctrl+b
[
to enter copy mode. Then hitSpace
followed by whatever vi movement keys to make a selection. Then, instead of hittingEnter
, hity
and the selection will be copied to the clipboard.Note: this assumes you're using tmux's default bindings with vi keys.
Tmux has different key binding tables for different modes. So,
bind-key -t vi-copy y
sets the action for they
key in copy mode. Initially, I was confused because I was used to hittingEnter
after making a selection.Enter
is actually just the default key binding for thecopy-selection
command (when in copy mode). Thecopy-pipe
command allows us to bind a new key to pipe the selection to a command, which in this case isxclip
.You can see all key bindings for copy mode by running
list-keys -t vi-copy
.