Using tmux to copy text between two sessions

July 5, 2012

As I mentioned in my previous post, I did not yet find a problem where I could effectively use the cut-paste between tmux buffers. But now I do. This post will describe the steps to copy text from one of your remote session to local session using tmux buffers.

NOTE: You can probably do the same using Mac OS X buffer (using mouse to select text and Cmd-C/Cmd-V). This post will show you a way without moving your hand away from your keyboard, which I believe is much more efficient. If you are Linux/*nix, check out this stackexchange question.

setw -g mode-keys vi
unbind p
bind p paste-buffer
bind -t vi-copy v begin-selection
bind -t vi-copy y copy-selection
bind -t vi-copy Escape cancel
bind y run "tmux save-buffer - | reattach-to-user-namespace pbcopy"

Here is a perfect use case example.