Unified clipboard between Neovim and Windows WSL2

Published at

#linux #neovim #terminal-shell #windows #wsl2

This TIL is more than a year old. Some details may have changed.

Install win32yank.exe

SHELL
$ curl -sLo/tmp/win32yank.zip https://github.com/equalsraf/win32yank/releases/download/v0.0.4/win32yank-x64.zip
$ unzip -p /tmp/win32yank.zip win32yank.exe > /tmp/win32yank.exe
$ chmod +x /tmp/win32yank.exe
$ sudo mv /tmp/win32yank.exe /usr/local/bin/

Remember to restart shell, to cache binary. I experienced not being able to access it straight after download and move.

Configure Neovim

TEXT
" Unified clipboard WSL2
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,
           \ }

Source: Neovim FAQ