Copying between tmux buffers and the system clipboard
One of the initially confusing things about tmux is that it has it's own set of buffers for copying and pasting data. Copying in tmux is easiest if you're using vi mode:
Then you can copy with the following operations:
*
-[ * go into copy modev go into visual select mode, select some text with the arrow keys
y copy the highlighted text
That takes you out of copy mode, and you have the copied text in your first tmux buffer. You can paste the buffer with <Prefix>-]
. The top buffer is always the most recently selected text.
You can see all of your tmux buffers with <Prefix>-#
, or the shell command tmux list-buffers
. You can also select and paste any of these buffers with <Prefix>-=
.
Working with the system clipboard
This is fine, until you want to copy something in the terminal to then paste in your browser or editor. Tmux's buffers are totally independent of your system's clipboard, so copying in one doesn't affect the other.
I've added a shortcut that works on systems that use xclip for the system clipboard (e.g. Debian). It copies the top tmux buffer to xclip's clipboard, and is bound to a keyboard shortcut:
If you add this to your tmux.conf file then you can use the shortcut <Prefix>-y
to copy whatever is in your top tmux buffer to your system clipboard.