Friday, November 16, 2007

Copy Text to OS Clipboard

This is a nice feature if you are editing using vertically split windows and want to copy the contents of a single window to your OS clipboard. In regular Vim or Gvim, go into visual mode, and highlight the text you would like to copy to your clipboard. Then, yank the text as follows, "+y. It should now be available to any application that uses your standard clipboard.


Unknown said...

Thank you for this information.

I had also problem with my copy/paste operation between my GVIM 7 and my Windows Environment.

By insering...

set clipboard=unnamed my vimrc file, I was able to play with my clipboard operation back and forth vim and windows.

joshyv said...

this doesn't work for me. i am on a leopard machine. it would be great if it worked. thanks....

Anonymous said...

thanks, this is great!

if anyone is having problems getting this to work, make sure you're pressing

1. shift and single-quote to actually enter the double-quote, then

2. shift and equals to actually enter the plus sign, then

3. (lowercase) y, then

4. the usual yank commands.

for example, if you want to copy the entire file into your clipboard, type in this order:

gg " + y G

this takes you to the first line of the document, then copies to the last line in the file to your clipboard. Go to text edit, notepad, etc. then ctr-v

Ember said...

If this isn't working in console vim, it's probably because xterm support wasn't compiled in. In Gentoo the USE flag is vim-with-x. After I rebuilt with that, the trick worked fine. Thanks! (I've been wondering how to do this for some time.)

Anonymous said...

Many thanks, no more need to run notepad when there's some copying to do!