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
.
Did you try to map with this command:
? 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: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 (+
).All the mapping they talked about was just map simple copy y to "+y. But most the time, the problem is that even "+y doesn't work.
So you need to check whether certain flag is enabled in your system right now.
vim –version | grep xterm_clipboard
sudo apt-get install vim-gnome
, thensudo update-alternatives –config vim
, select vim.gnome in the list. (You should use the proper command that corresponds to your system) Run the commandvim –version | grep xterm_clipboard
, now you should be able to get + (plus sign). Otherwise, use Google to see what’s going on...clipboard=unnamedplus
to your .vimrc. If it’s a * (star sign), add set clipboard=unnamed to your .vimrc.:reg
to check whether the system clipboard has changed. If it does, your will get whatever is in that register when you’re doing Ctrl-V outside of vim.I have the very same idea as you, but I did it for years.
Note that now
yy
command does two things: First it yank to register as normal, and then it yank to"
register (system clipboard). They
command does the same thing. This is because I want to keep the multiple clipboard functionality of Vim.For pasting from system clipboard, I used to have
noremap gp "+p
(global pasting), but now I use the excellent plugin Yankring.Select some text in visual mode and it will be inserted into the system clipboard (the one where you middle-click to paste, I cannot recall the exact name).
If you
set mouse=a
you can use the mouse for visual selection like you would in many other applications.In my case, I can sometimes copy from gvim to the system clipboard and sometimes not. I found a workaround, though I don't understand the underlying problem. If I copy text in another application (e.g. Notepad, as I am on Windows 7), then I can copy text from gvim and paste it elsewhere. It looks I need do this for each copy out of gvim.