Copy From Vim to System Clipboard and Vice Versa

Copying text from vim to the system clipboard and pasting text from the clipboard in vim can be done simply by yanking to/pasting from special vim registers.  ”*” and “+” (without the quotation marks of course).

The register “*” is connected to the selection buffer, and “+” is connected to the clipboard.

To make sure your vim is compiled to support this feature, run the following command

vim --version | grep xterm_clipboard

you should see +xterm_clipboard.  If you see -xterm_clipboard instead, then you need to do something about it.

I use Ubuntu 10.10, the default vim doesn't support copying to/pasting from the system clipboard. It can be enabled easily though:

Install vim-gnome

sudo apt-get install vim-gnome

Make it the default vim

sudo update-alternatives --config vim

You'll see a list choose vim.gnome (by typing its number in the list).

Done. Now open vim. You can talk to the system clipboard like in the following examples:

copy current line to clipboard:


paste clipboard to vim


You got the idea. Have fun.

Leave a Reply