7

Note: this question is specific to the relatively new Ubuntu Bash on Windows system.

So it seems possible to paste into Vim from the Windows clipboard by simply right clicking in insert mode after enabling the Quick Edit Mode option.

But has anyone figured out how to paste into Windows something that was copied using Vim?

I've tried using the "* and "+ registers, but it seems as though they aren't even present. I ran :reg and only saw the "", "0, "., ":, "/ registers. Are other people at least seeing the registers? Or is it just me?

Also, my version of Vim has the +clipboard and +xterm_clipboard features installed.

What I can do is use the mouse, select text in vim, then right click to copy, then paste like normal in Windows. But I'd really rather just yank items in Vim into the Windows clipboard.

2

2 Answers 2

11

Thank you to @Christian Brabandt for linking this in the comments: https://www.reddit.com/r/vim/comments/7pmv3d/workflows_that_work/dskyram/

Works great. Just put the following in your vimrc and make sure to have vim version >= 8.0.1394

" WSL yank support
let s:clip = '/mnt/c/Windows/System32/clip.exe'  " default location
if executable(s:clip)
    augroup WSLYank
        autocmd!
        autocmd TextYankPost * call system('echo '.shellescape(join(v:event.regcontents, "\<CR>")).' | '.s:clip)
    augroup END
end
1
  • Excellent! This made life much easier.
    – Gergely
    Mar 21, 2021 at 10:33
0

If you're on Windows 11, WSL has an X server configured out of the box. The steps required for copy-paste are reduced simply to:

sudo apt install vim-gtk

This switches the installed options from -clipboard to +clipboard, and "+y will work immediately. "*y still doesn't work. I'm not sure why.

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.