Copying text from Vim to the system clipboard

Copying text from Vim to the system clipboard

How to copy text to paste elsewhere by using xclip

To copy text from Vim to the system clipboard I use xclip with this command:

xclip -sel clip

To copy the whole file I use % to represent the file and write it to the xclip command:

:%w !xclip -sel clip

When I want to copy a selection only, I make the selection first in the usual ways and then write that selection to the same xclip command:

:'<,'>w !xclip -sel clip

I am then able to paste the clipboard in another program using either the mouse or CTRL-V.