3

To get this off the table now and avoid any confusion ... This is for Linux running in Windows 10(ubunutu), also known as WSL. Its not the same as cygwin and windows or stand alone linux. It is it's own beast.

So please keep the above in mind before I am referenced with all the articles I have already read or comment that this has been asked before.

Does anyone know how to make the copy and paste work off of the windows clipboard OR the WSL Ubuntu Linux emulation? I am using set clipboard=unnamedplus. It's not working, not matter what combinations I use like yy, "+yy, etc.

Yes, it's vim-gtk with +xterm_clipboard support.

  • If you're running Win10 pre-1709, then WSL is beta software obtained through the developer channel. Since then, the official release is Ubuntu (or OpenSUSE) available through Linux on Windows from MS Store. Despite your clarification, it's not clear which you're running. That said, I've found that the standard cmd terminal clip-board handling seems to work on both. – AFH Feb 2 '18 at 16:57
  • No, this is most recent...non beta..from the store. I just installed it 3 days ago. I can't get vim to use the clipboard (rather it be windows or linux ...not sure which would be used in the unique WSL case). – dman Feb 2 '18 at 16:59
  • 1
    It works for me in 1709: I have configured the bash terminal for Quick Edit mode and I use click and drag to select, right-click to copy selection and again to paste. – AFH Feb 2 '18 at 17:11
  • 1
    @AFH yep... I used to be able to do this with two separate cygwin sessions using the windows clipboard registers. Any ideas on how to do it in WSL? – dman Feb 7 '18 at 22:42
  • 1
    perhaps this does it? vi.stackexchange.com/q/15182/71 – Christian Brabandt Mar 13 '18 at 16:00
3

This solution worked for me, thanks to github user robbiev.

For completion this is an outtake from his answer:

  1. Install VcXsrv (if it starts after installing, stop it).
  2. Start it using the newly installed program XLaunch (search in the start menu).
  3. Go with all the defaults options, and ensure the clipboard options are checked.

  4. At the end, save the configuration to a file, config.xlaunch (use that to start it from now on).

  5. Put export DISPLAY=localhost:0.0 in your .bashrc in bash for Windows and run source ~/.bashrc in any open terminal.

  6. Ensure vim is installed using clipboard support. vim --version | grep clipboard should say +clipboard, not -clipboard. Also if you run the ex command :echo has('clipboard') in vim and it says 0 it does not have clipboard support compiled in.

  7. If you don't have clipboard support, install a vim package compiled with clipboard support, e.g. apt-get install vim-gtk.

  8. Now you can access the Windows system clipboard via "*p and "*y, or set it to default by putting set clipboard=unnamed in your .vimrc file.

As robbiev mentions you should now also be able to use the Windows clipboard from remote machines using SSH X forwarding.

  • The joy when you (me) face with same problem 4 months later, google it and your (mine) past self helps you fix it! – Aerows Nov 20 '18 at 17:06
1

If you have enabled the QuickEdit Mode, you can just select the text with your mouse and right click to copy it into the clipboard.

For enabling the QuickEdit Mode, just right-click on the console windows on top and select Properties (and/or Default), then tick QuickEdit Mode.

EDIT: Out-of-the-box, it is not possible to copy from VIM into Windows clipboard currently. However, on a GitHub-Issue within the WSL repository, some guys seem to have found a way to do that using Xming or VcXsrv respectively: https://github.com/Microsoft/WSL/issues/892#issuecomment-275873108.

EDIT2: Another try using .vimbuffer: https://stackoverflow.com/questions/44480829/how-to-copy-to-clipboard-in-vim-of-bash-on-windows

  • no, the whole idea is to use the vim commands yy and not have to use the mouse. – dman Mar 9 '18 at 17:12
1

There are lots of quirks with WSL terminal, but using cross Vim copy/paste is top annoyance in my book. Nothing I tried as of April 2018 worked for pasting into Vim or other areas (using normal saneness) so, let's try to bypass the issue, and others related like buffer, for now. This is not a direct WSL solution, rather a workaround using a better terminal + SSH until MS provides a fix.

Putty, or it's extended fork Kitty, offer a more robust terminal compared to WSL. We can connect to the WSL (or any of your other servers) using SSH via localhost, using a custom port, and get a fuller featured terminal, including almost all Vim capabilities for bi-directional, or native pasting, scroll, etc. [You may need to tweak Vim conf to trigger all capabilities].

Putty/Kitty require an SSH server available in WSL, on a custom localhost port. If you haven't set up a localhost SSH server on your WSL already, here's a quick overview of how:

Step 1) Open the Ubuntu WSL terminal, do a sudo su to auth as root, run vim /etc/ssh/sshd_config to open SSH server conf.

Step 2) Look for "Port" near the first handful of lines. It may be set to 22. We need to set a custom port for our WSL SSH that doesn't collide. Hit i to edit. Let's use port 9977 for example.

Step 3) If you're a dev, or otherwise don't need to bother with keys for your localhost WSL SSH, look for password authentication. You can set PasswordAuthentication yes. Else, keys and higher security, or public access through firewall(s) on WSL, are beyond the scope of this answer.

Step 4) When done editing, hit esc to exit edit mode, then save+quit the file :wq. Restart ssh service using service ssh restart. Leave WSL open at this point as a master console.

Step 5) Create a new Putty/Kitty session, connect to localhost, using your custom port (9977 in our example). Log in with your WSL credentials, sudo su if you require root. You should now have a much more robust shell available. Repeat or screen as many views as you need.

I know it's not a direct answer, but at least it's a solution for now :)

  • How do you get Xlaunch to start VcXsrv? It defaults to Xming for me – dman Nov 8 '18 at 14:27
1

A partial solution through ConEmu

Not sure why nobody mentioned ConEmu. It can at minimum handle one-half of the clipboard issue:

  • To paste Windows clipboard stuff into WSL, normal Ctrl + V will get things right.

    • One perk is that: if one is to copy an absolute path in Windows, when pasting in ConEmu, c:/users/name will be transcribed into /mnt/c/users/name. This is runnable through WSL natively.
  • To copy from WSL, for now, I would still have to use my house cursor. It works more than 90% of the times.

Per my use case, I don't tend to copy from WSL a lot; and have been enjoying the pasting-help by ConEmu a lot.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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