Vim is pre-installed on both OSX and Linux, but the version may not have the +clipboard option, which allows copy/pasting between Vim panes in tmux (see this post for an intro to tmux). Copy/pasting between panes is a really useful feature, so it is worth spending ten minutes to make sure this option is available.

This post describes how to install a version of Vim which has the +clipboard flag for OSX.

There is also another post describing how to enable this option in Linux.

Checking Vim clipboard

The Vim that comes with OSX probably does not have the +clipboard flag installed. Try:

vim --version | grep clipboard

If you see something like:

then this is bad; we need +clipboard to indicate that the clipboard is accessible to Vim (do not worry about -xterm_clipboard).

Installing Vim with Homebrew

So, install a new version of Vim using brew:

brew install vim

Modifying the bash_profile

Very important - we want to make the installed Vim easily accessible, so we create an alias in the bash_profile, by adding the following line:

alias vim ='/usr/local/bin/vim'

This can also be done on the command line with the following line:

echo "alias vim ='/usr/local/bin/vim'" >> ~/.bash_profile

Reload the bash_profile

The reload the bash_profile using:

source ~/.bash_profile

then when checking the clipboard property:

vim --version | grep clipboard

we should see:

+clipboard -xterm_clipboard

Modifying the vimrc

Need to add the following line to the vimrc file:

set clipboard=unnamedplus,unnamed,autoselect

Please see this post for a minimal vimrc, and this other post for a slightly less minimal version.

If using iTerm2

Preferences-General-Selection-Copy to pasteboard on selection should be unchecked, according to this link.