22
votes

I need to paste some selected block in visual mode to outside of vim. Currently I need to select this block manually from mouse to paste outside of vim.

As selecting texts in visual mode is easier ,it would be efficient to select some text for pasting outside of vim.

5
"*y or "+y don't seem to work for me. I am using putty. Do I need any particular xwindow installation as pointed in answer by Edward?shampa
Checkout my answer here stackoverflow.com/a/65666057/9384511ABN

5 Answers

26
votes

You could yank the text into the + (plus) register, that is mapped to the system clipboard. Just select the text in the mode you like and then type "+y.

14
votes

Disclaimer: Linux

So what I have noticed is you need clipboard support compiled in to your vim. I ended up compiling my own vim, which had the clipboard support. To check run vim --version and look for a +clipboard or a -clipboard, if it's + then yay you have it, if it's - then you need to compile vim yourself or download a version with clipboard support compiled in. Then the answers people have said seem to work. For me "*y copies into the buffer that is pasted by pressing the middle button, and "+y copies into the buffer which is the normal control + c or on the terminal control + shift + c so what I put into my vimrc was

map <C-c> "+y

that way doing control + c me paste it somewhere else by pressing the exact same command

:wq

6
votes

If you are using GUI-based gvim, simply yank your text into the "clipboard register" by prefixing your yanking command with "+. That is, when you have finished selecting your text in visual mode, press "+y to yank your text then it will be in your system clipboard.

If you are using text-based vim and your vim has clipboard access to your current system, it's just the same as gvim. If your vim has no clipboard access, try to establish the clipboard connection as described in this page:

http://www.quora.com/How-can-you-copy-all-contents-of-a-text-file-opened-in-vim-through-Putty-on-a-Windows-desktop-to-Windows-clipboard

5
votes

You can bind contents of the visual selection to system primary buffer (* register in vim, usually referred as «mouse» buffer) by using

set clipboard^=autoselect
1
votes

You have to identify the register that vim is using to get the outside clipboard. First copy any text outside vim and then inside vim do the command :registers and look for the text you copied, once you have identified the register simply use it every time you need to copy and paste from the outside: for example: Im using gvim in Windows7 and the register used by vim to get the external clipboard is

*"

then in vim select the text and do

*"y to copy (yank) and paste outside as usual

and to paste inside vim from outside do *"p

you can also do a map to the register to easy copy/paste