Windows Subsystem Linux - Make VIM use the clipboard?

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.


(Edit: Oct 2020) For 2-way clipboard on neovim, I have been using win32yank for several months with no issues. Put win32yank.exe somewhere in your path on Linux (anywhere should be fine), and add the following to your init.vim.

set clipboard+=unnamedplus
let g:clipboard = {
          \   'name': 'win32yank-wsl',
          \   'copy': {
          \      '+': 'win32yank.exe -i --crlf',
          \      '*': 'win32yank.exe -i --crlf',
          \    },
          \   'paste': {
          \      '+': 'win32yank.exe -o --lf',
          \      '*': 'win32yank.exe -o --lf',
          \   },
          \   'cache_enabled': 0,
          \ }

(Original answer) If you just want to yank from VIM to Windows, for WSL2 and Ubuntu 20.04, this answer on Reddit worked perfectly for me with standard VIM and standard WSL2 Ubuntu.

Put the following in your .vimrc (at the bottom, for example):

" WSL yank support
let s:clip = '/mnt/c/Windows/System32/clip.exe'  " change this path according to your mount point
if executable(s:clip)
    augroup WSLYank
        autocmd!
        autocmd TextYankPost * if v:event.operator ==# 'y' | call system(s:clip, @0) | endif
    augroup END
endif

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.


You can right click the terminal then in the options box check CTRL + SHIFT + C/V for copy paste operations through the terminal.

WSL Ubuntu Terminal


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