This post discusses how to copy/paste between tmux panes and windows. See this post for more ways to customise tmux.

Copy-pasting between panes

The following shortcuts were taken from this very useful post, and allow easy coopy/pasting between panes.

#-------------------------------------------------------#
#Pane copy/pasting
#-------------------------------------------------------#
bind-key -t vi-copy 'v' begin-selection
bind-key -t vi-copy 'y' copy-selection
bind C-v paste-buffer
#-------------------------------------------------------#
  • In tmux, use prefix [ to switch to 'copy' mode. You can then press v to switch to 'visual' mode, and start highlighting text.
  • Use Vim keys b,w,h,l, etc, to highlight more text.
  • Use y to copy text to system clipboard.
  • Move to another pane/location.
  • Finally, use prefix Ctrl v to paste text in another pane.

It is possible to change the key-binding to enter 'copy' mode to prefix Esc (as in Vim) using the following:

unbind [
bind-key -t vi-copy 'v' begin-selection
bind Escape copy-mode

but I prefer not to use this binding; it seems unnecessary.

Note: One could alternatively bind prefix p to be paste, but this would overwrite the command which changes windows to the previous window. I prefer to use prefix Ctrl v, which may be familiar for ex-Windows users.

Note: to exit 'copy' mode, simply press Enter.

Note: This post shows that the default commands for OSX are:

  • prefix [ - enter copy mode
  • Enter - copy
  • prefix ] - paste

Copying to system clipboard

Initially, I thought that copying in a tmux pane would place the text in clipboard (which I could then paste in a browser, Notepad/Textedit, etc), but this is not the case. Perhaps I am missing an extra command (update soon!).

My current workaround is to copy/paste from a tmux pane into a Vim pane, and then copy again from the Vim pane - this will place the text in the accessible system clipboard.

In my .vimrc file, I have set copying from Vim to clipboard to be the F2 key using:

nmap  :.w !pbcopy
vmap  :w !pbcopy

This is not entirely satisfactory, so hopefully I will find a fix for this and update this post soon.