Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gvim: Easy copying into system clipboard

I am using gVim on Ubuntu 10.10. I want to copy (yank) text to the system clipboard, so that the copied text is available in other applications.

This works with "+y. But I want to have it working with y.

I have tried to map y to "+y but then yy doesn't work anymore (since it produces "+y"+y).

I have also tried :set clipboard=unnamed but this works only the other direction: Text in the system clipboard I can paste with p.

like image 464
Georg Jähnig Avatar asked Dec 25 '10 23:12

Georg Jähnig


People also ask

How do I paste from Gvim to clipboard?

Press v to select characters, or uppercase V to select whole lines, or Ctrl-v to select rectangular blocks (use Ctrl-q if Ctrl-v is mapped to paste). Move the cursor to the end of what you want to cut. Press d to cut (or y to copy). Move to where you would like to paste.

How do I save to clipboard in Vim?

In vim command mode press v , this will switch you to VISUAL mode. Move the cursor around to select the text or lines you need to copy. Press y , this will copy the selected text to clipboard.

How do I enable clipboard in Vim?

You need to make sure clipboard is activated (which is probably not the case). if you get "-clipboard" then you would have to install vim again with the "clipboard" functionality. You can do it it by installing "vim-gtk3" or "gvim".

How do I copy and paste from Vim to Notepad?

In this mode, you can run Vim commands and navigate through the file. To go back to normal mode from any other mode, just press the Esc key. Vim has its own terminology for copying, cutting, and pasting. Copy is called yank ( y ), cut is called delete ( d ), and paste is called put ( p ).


1 Answers

Did you try to map with this command:

noremap y "+y 

? This mapping contains a serious mistake: it maps y in normal, visual and operator-pending modes, while you need only normal and visual modes. Use the following:

nnoremap y "+y vnoremap y "+y 

Also try set clipboard=unnamedplus (it requires at least vim-7.3.74). set clipboard=unnamed works in both directions, but it sets «mouse» (*) register which is different from clipboard register (+).

like image 129
ZyX Avatar answered Oct 07 '22 07:10

ZyX