Getting tmux to copy a buffer to the clipboard
This should work:
# move x clipboard into tmux paste buffer
bind C-p run "tmux set-buffer \"$(xclip -o)\"; tmux paste-buffer"
# move tmux copy buffer into x clipboard
bind C-y run "tmux save-buffer - | xclip -i"
A simpler solution for Mac OS-X
This builds off of Alex's answer and uses stuff that didn't exist at the time.
If you are using homebrew (and if you aren't, why aren't you?) then you can just do this:
brew install reattach-to-user-namespace
Then in your ~/.tmux.conf
:
set-option -g default-command "reattach-to-user-namespace -l zsh" # or bash...
bind C-c run "tmux save-buffer - | reattach-to-user-namespace pbcopy"
bind C-v run "reattach-to-user-namespace pbpaste | tmux load-buffer - && tmux paste-buffer"
To copy the buffer from tmux (you should have already copied something using tmux) into the Mac pasteboard, use <tmux-key> Control-c
. It will now be available for Command-v
or pbpaste
To paste something from the Mac pasteboard, use <tmux-key> Control-v
.
The copy-pipe
command was added as of version 1.8. It copies a selection to the tmux buffer and pipes it to a command. Now there is no need for a prefix binding. Here's an example:
bind -t vi-copy y copy-pipe "xclip"
# For OS X users:
bind -t vi-copy y copy-pipe "reattach-to-user-namespace pbcopy"
Now when you have some text selected in copy-mode
, y will copy that text to the tmux buffer as well as the OS clipboard. However, it doesn't help if you want to get text from the clipboard to the tmux buffer.