How to copy and paste using clipboard in Vim

You can use the clipboard of your desktop or X from Vim to copy and paste text. This is useful to copy text from Vim to an external application or vice versa. It is also useful if you are using multiple splits or tabs of terminals with Vim running inside them and wish to copy and paste between these multiple instances of Vim.

These capabilities are available in Vim if it has been compiled with the +clipboard feature. Most modern builds of Vim have this feature. The doublequote-plus register "+ is connected to the system clipboard in Vim. Anything you cut, copy or yank to it appears in the system clipboard. The text in the clipboard appears in Vim, if you paste from this register.

To copy to system clipboard, visually mark the text and type: "+y

To paste from system clipboard: "+p

Note that Vim may be copying everything you visually mark to clipboard by default. This is because most Vim builds have the autoselect feature turned on. This autoselect feature can be disabled if you wish to.

Tried with: Vim 7.4 and Ubuntu 14.04

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s