Skip to content

Instantly share code, notes, and snippets.

@robbiev
Created April 14, 2017 16:22
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robbiev/1f139c0d41806bc1e84a3543941f5029 to your computer and use it in GitHub Desktop.
Save robbiev/1f139c0d41806bc1e84a3543941f5029 to your computer and use it in GitHub Desktop.
clipboard access for WSL / bash on Windows

For those who want to go the X server route, let me leave my notes here.

  1. Install VcXsrv (I found that Xming is outdated on sourceforge and the new version is donationware)
  2. If it starts after installing, stop it
  3. Start it using XLaunch (search in the start menu), go with all the defaults (ensure the clipboard options are checked)
  4. At the end, save the configuration to a file (use that to start it from now on)
  5. Put export DISPLAY=localhost:0.0 in your .bashrc in bash for Windows (and run the command in any open bash windows). The reason I explicitly say localhost is that this makes SSH X forwarding work, see below.
  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. If you don't have clipboard support, install the vim-gtk package (apt-get install vim-gtk).
  7. It should now work

As a bonus you should now be able to copy from and to your Windows clipboard from a remote machine by using SSH X forwarding (ssh -X ... ). You can use xclip on the remote machine or if you use vim there you will again need to make sure the clipboard option is compiled into vim (e.g. install vim-gtk). You can probably also configure PuTTY to use your local X server in case you prefer using that for remote connections.

@johnnymatthews
Copy link

Just a heads up, this might not work with WSL 2. To find out which version of WSL you're working on, open Powershell and run:

wsl -l -v

> NAME            STATE           VERSION
> * Ubuntu          Running         2
>   Ubuntu-20.04    Stopped         2

If you're Ubuntu version says 2 (Ubuntu, not Ubuntu-20.04) and you can't grab a copy of your pass passwords, try downgrading to WSL version 1:

wsl --set-version Ubuntu 1

It'll take a couple of minutes to finish, but once it has you should be and to access your Windows clipboard through WSL (assuming you've followed the steps by @robbiev above).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment