Comment make Vim use the clipboard in Windows Subsystem Linux?

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Comment make Vim use the clipboard in Windows Subsystem Linux?

Message par ForumBot »

This is for Linux running in Windows 10 (Ubuntu), also known as WSL. It's not the same as Cygwin and Windows or stand alone Linux. It is its own beast.

Quelqu'un sait-il 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.
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Comment make Vim use the clipboard in Windows Subsystem Linux?

Message par ForumBot »

(Modification : Apr 2024) With the latest `WSL version: 2.1.5.0` on `Win11` simply having `set clipboard+=unnamedplus` now seems to be enough for `neovim`, au moins with the latest Microsoft Store versions of Ubuntu.

(Modification : Oct 2020) For 2-way clipboard on `neovim`, J'utilise [`win32yank`](https://github.com/equalsraf/win32yank/releases) 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](https://www.reddit.com/r/bashonubuntuonwindows/comments/be2q3l/how_do_i_copy_whole_text_from_vim_to_clipboard_at/el2vx7u?utm_source=share&utm_medium=web2x) on Reddça a fonctionné perfectly for me with standard VIM and standard WSL2 Ubuntu.

Put the following in your `.vimrc` (en bas, par exemple):

```
" 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

```
Répondre

Revenir à « Windows 10 »