Last Updated: February 25, 2016
· brianriley

Access the system clipboard from vim

Make terminal vim a first-class citizen with access to copy to/paste from the system clipboard. First off, check that vim was complied with clipboard support:

$ vim --version

If you see +clipboard, then you're good to go. If you see -clipboard, then you need to compile vim with clipboard support. (On OS X, brew install vim will give you vim with clipboard support.)

Next, in your .vimrc, add:

set clipboard=unnamed

Restart vim and enjoy!

Further reading: Accessing the system clipboard

3 Responses
Add your response

How do you access it afterwards?

over 1 year ago ·

This solution has the side effect that vim will "pollute" your system clipboard. Whenever you yank or remove lines, those lines will replace the system clipboard or append to system clipboard history if you rely on that also.

My solution is easier access to system clipboard:

map <space>y "+y
map <space>p "+p
map <space>P "+P
over 1 year ago ·

Polluting the system clipboard is the intention here. If you yank in vim, you can then Cmd+P anywhere else to paste.

over 1 year ago ·