21

I know how to copy in Vim. but I failed to copy it into other application. That means I failed copy those into clipboard. How can I do this?

P.S. In order to learn more. I also want to ask how to copy content from clipboard to vi.

Edited: I am using macOS.

It seems *yy doesn't work here. Any other ways?

1
  • 2
    If you are on MacOS have you tried MacVim? It's a really great port of Vim that lets you use standard cmnd+C, cmnd+V for the clipboard, since the cmnd key does not interfere with Vim in any way. MacVim is pretty much my all time favorite editor :) Commented Apr 3, 2011 at 22:24

4 Answers 4

36

You need to use the clipboard register, which is *, so to copy a line of text into clipboard:

"*yy 

To paste a line of text from the clipboard:

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

3 Comments

This works for vi, but doesn't work for libre office or notepad. If VI puts it in the buffer, should this work for any application?
Yes, the * buffer is system-wide, it's the same buffer used by Ctrl-C and Ctrl-V. Are you using Vim, or plain old vi?
Excuse me, I tried this method and this works when your file is in your system but when you are working with a remote machine it does not work. Do you have any idea easier than scp?
26

"+y or "*y works only if your vim supports the xterm_clipboard. Xterm is a terminal emulator for X11. Try vim --version to see if it is supported. If you see +xterm_clipboard it should work, if you see -xterm_clipboard it won't. Now there are many Linux flavours which still have the xterm_clipboard support deactivated in their repositories. Yanking via clipboard is then impossible. Note that you still have the good old unix style of yank/paste, namely select the text you'd like to yank and middle-click on the mouse where you want to paste. This should work always and is the preferred style of yank/paste in vim. Be sure to be in insert mode and type set paste if it screws up the indentation. set nopaste to leave paste mode.

To get vim with xterm_clipboard, simply download the source, make a ./configure --with-x and then a make. Now vim should support xterm_clipboard and yanking and pasting should work flawlessly also from the clipboard.

Comments

5
"+yy or "*yy to copy to clipboard "+p or "*p to paste from clipboard 

The " will put it into the + register.

For even more than you wanted to know: http://vim.wikia.com/wiki/Accessing_the_system_clipboard

Comments

3

The copy of vi is done within vi's own internal clipboard, as its descended from the unix command line where the windows style clipboard didnt exist. Later came the mouse pointer for command line which meant you could copy using that as a more like windows style, but if you want to copy from vi to windows clipboard, you need to use *yy and *p, not yy and p which are the internal clipboard within vi (which is also why yanking and pasting dont effect your windows clipboard)

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.