21

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.

Vadim Kotov
  • 7,103
  • 8
  • 44
  • 57
shampa
  • 1,200
  • 3
  • 11
  • 21
  • 4
    "*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 Oct 13 '11 at 00:58
  • 1
    Checkout my answer here https://stackoverflow.com/a/65666057/9384511 – ABN Jan 11 '21 at 12:46

5 Answers5

26

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.

etuardu
  • 4,301
  • 3
  • 41
  • 53
13

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

Jacob Minshall
  • 964
  • 8
  • 14
6

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

Lifu Tang
  • 1,193
  • 8
  • 11
5

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
ZyX
  • 49,123
  • 7
  • 101
  • 128
  • this gvim much more convienient in combination with a terminal, especially if you have set behave mswin, thanks – joe_zeroh Jul 17 '13 at 15:55
1

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