How to copy and paste using clipboard in Vim

You can use the clipboard of X or your desktop 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 to copy and paste between multiple instances of Vim running in different terminals.

This capability is available in Vim only if it has been compiled with the +clipboard feature. With this feature, the doublequote-plus register "+ of Vim is connected to the desktop clipboard. Anything you cut, copy or yank to this register appears in the system clipboard. If you paste from this register in Vim, then the text in the clipboard appears.

  • 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.

  • This feature just does not work on some systems for me. I have resorted to using xclip to copy and paste between Vim and desktop clipboard.

Tried with: Vim 7.4 and Ubuntu 16.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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.