Polb
Polb

Reputation: 700

Pasting from clipboard in vim

I am trying to paste a string I copied from a webpage in vim. I know that the string is copied in the system clipboard. My vim returns 1 when I run the :echo has('clipboard') command, so I typed :set paste, then positioned the cursor to the desired spot and hit "*p, but this doesn't seem to paste my whole selection. I copied to the clipboard Vader(father figure) but it only pastes Vader. Or is it pasting this because the word behind the cursor is Vader? And finally, what is the easiest way to paste something in vim from the system's clipboard?

I mention that I am using Ubuntu 14.04 (if this has any relevance).

Upvotes: 1

Views: 7874

Answers (4)

Giuseppe Ricupero
Giuseppe Ricupero

Reputation: 6272

I'm currently using the system clipboard in vim as default register in combination with a clipboard manager like Diodon or Klipper (for KDE).

Add this to your vim configuration ~/.vimrc

" Use the system clipboard for yank / delete / paste operations 
if has('unnamedplus')
   set clipboard=unnamed,unnamedplus
endif

With this configuration vim copy/paste operations (in both directions) behave just like in any other graphical editor (the if has ('unnamedplus') assure that this behaviour is enabled only if vim is compiled with the +clipboard option otherwise behaves as default).

Note: on Windows and MacOS using unnamed or unnamedplus is equivalent.

On Linux are two different entities:

  • unnamed register is the selection buffer (try to select something with the mouse and then center click or click both sx and dx mouse buttons in another place).
  • unnamedplus register is actually the system clipboard

Upvotes: 0

Vitor
Vitor

Reputation: 1976

You only need to set paste if you intend to paste while in insert mode using the middle mouse button or any shortcut your terminal provides.

Now, it is possible that the register you're looking for is quote+. To confirm that just run :registers in order to view the contents of all registers.

I would also advise you to read the following help section :help x11-selection.

Upvotes: 0

avinashkrsharma
avinashkrsharma

Reputation: 143

I always use Ctrl+Shift+v in Insert mode, when pasting from system clipboard after doing set paste. Never had any problems doing so.

Otherwise you can use the vim-unimpaired plugin by tim pope and use the yo key mapping set by the plugin to paste. Using yo automatically sets the paste option and after you paste and leave Insert mode, it automatically toggles the set paste option.

Upvotes: 1

Bharat
Bharat

Reputation: 297

Have this line in your .vimrc

set pastetoggle=<F2>

So whenever you press F2 in insert mode you can paste normally with no problems. For more information refer here.

Upvotes: 1

Related Questions