22

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.

2
  • 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? Commented Oct 13, 2011 at 0:58
  • 1
    Checkout my answer here stackoverflow.com/a/65666057/9384511 Commented Jan 11, 2021 at 12:46

5 Answers 5

28

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.

Sign up to request clarification or add additional context in comments.

Comments

16

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

2 Comments

This one makes sense!
For anyone landing here using MacOS, this works on Mac as well, using the brew-installed Vim
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

Comments

6

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 Comment

this gvim much more convienient in combination with a terminal, especially if you have set behave mswin, thanks
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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.