3

I've found a lot of information online about this for Linux-Vim but not for the Windows-Vim (not gvim). Whenever I try to copy and paste something in Vim (using y and p), the copies I make do not expand to the system, only to the currently running instance of vim. Here are a few different scenarios that all do different things:

  1. Copying-and-pasting like normal in the command prompt (by highlighting to copy and right-clicking to paste) works as expected - it copies to and pastes from the system clipboard

  2. If I copy abc in notepad, I can paste abc in any opened vim with p or "*p or "+p. But if I copy 123 from one instance of vim with y, "+y, or "*y, I can paste 123 in that instance, but if I switch to another, abc will paste instead of 123.

Based on what I've read, this is because Vim places the data in a register, but the register doesn't get transferred to the windows clipboard. However, I haven't been able to find any information online about why, everything is limited to the Linux version.

I've tried using :set guioptions+=a as mentioned here but that doesn't seem to work. Also, +clipboard returns 1, so I believe it should be enabled.

2
  • Just to be sure: when you yank and paste your text do you specify the register like "*y "*p?
    – statox
    Commented Jun 26, 2019 at 15:31
  • 1
    @statox Yes, I've added those details to the question.
    – Jon
    Commented Jun 26, 2019 at 15:56

2 Answers 2

2

I don't have a Windows machine to test, but I think you are looking for

:set clipboard=unnamedplus

Than Vim always uses the + register "for all yank, delete, change and put operations which would normally go to the unnamed register".

See :help clipboard.

1

I've found a lot of information online about this for Linux-Vim but not for the Windows-Vim (not gvim).

There's no much difference really, except Windows has only one clipboard, so both * and + could be used interchangeably.

If I copy abc in notepad, I can paste abc in any opened vim with p or "*p or "+p

Just p uses so-called unnamed register, which is basically an alias for the last register used. That means it may accidentally work for the system clipboard, but, in general, it does not. On the other hand, both "*p and "+p always put the contents of the system clipboard at the cursor position.

But if I copy 123 from one instance of vim with y, "+y, or "*y

The same, of course, applies to yanking. The unnamed register, in general, is not visible outside of the current instance of Vim. But + and * are.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.