0

Problem definition

  • My goal is copy code from vim and paste to browser.

It doesn't work as expected "+y and "*y command.

I have tried each two commands and tried ctrl + v to another application, but nothing happened.

I don't know what's problem.


What I tried

  • I've already seen these.
  1. How to make vim paste from (and copy to) system's clipboard?

  2. How can I copy text to the system clipboard from Vim?

Not only these but also lots of another Q&As.

I have tried these but still doesn't work.


My environment

I'm using Windows 10. And on windows, I installed Ubuntu 20.04 and using VIM.

Result of vim --version | grep 'clip' is here. +clipboard

As you see, clipboard and xterm_clipboard option is enabled.

And as said another Q&A of links, I append set clipboard=unnamedplus into my vimrc file.

But the result did not change.

  • Why can't you highlight things on vim with your mouse and then do regular ctrl+c, ctrl+v? – wxz Jul 01 '21 at 20:22
  • Because vim doesn't support system clipboard usually. So I make sure vim to use system clipboard, (in screen shot image, '+clipboard' option is on) but nothing changed :( – dkdlelk99 Jul 02 '21 at 05:00
  • I just tried it on my Windows 10 with Ubuntu on WSL and `ctrl+c` on something in `vim` that's highlighted by my mouse, and then doing `ctrl+v` (I pasted into Notepad) works. – wxz Jul 02 '21 at 13:31

1 Answers1

0

As I understand you want to copy from vim in WSL to Windows. Unfortunately WSL and Windows have different clipboards, but this is solvable. For example in order to copy file contents from WSL to Windows clipboard, you need to pipe file contents to clip.exe:

cat myfile | clip.exe

So in vim we can:

  1. yank your selection
  2. Drop to command line and type :! echo
  3. Paste the selection with Ctrl + r "
  4. Continue typing in the command line: | clip.exe
  5. hit Enter and profit!

Probably it would be useful to write some autocmd for this in vimrc.

Draco Ater
  • 20,820
  • 8
  • 62
  • 86