Clipboard sync between WSL Neovim and Windows
Written on
I recently started migration from Vim to Neovim. One of the first issues was proper configuration of clipboard. By proper, I mean a situation where I have a working 2-way-sync clipboard between Neovim running in tmux in WSL in Windows Terminal and Windows, so I can easily copy and paste from my browser or any other program to and from Neovim.
With Vim I intially achieved that with GWSL
and configured $DISPLAY
env variable
which was a quite complex and unstable solution
(GWSL sometimes has weird issues).
Thankfully, it was needed only on older versions of Windows 10
(my $CURRENT_COMPANY
still uses the old Win10 version though…).
Up-to-date Windows 10 and Windows 11
support clipboard sync for Vim out of the box.
They have something like GWSL built-in,
and surprisingly it’s quite stable and just works.
Bravo Microsoft 😛
The only caveat is to install Vim version which has clipboard support – usually vim-gtk
is recommended on Debian/Ubuntu.
The unexpected
I was a bit surprised to find out that this doesn’t work with Neovim.
Some googling brought the solution: win32yank
.
This is a small Rust program
which integrates with Windows cliboard,
providing an interface which can be easily used by Neovim.
Actually, Neovim has built-in support for it.
You just need to make sure that win32yank.exe
is on your $PATH
.
How to get win32yank.exe
?
I use WSL to do most of my text editting, but I still find it useful to have the same editor on Windows itself.
You can install it most easily with
winget,
i.e. winget install Neovim.Neovim
.
Why this it important?
It turns out that Neovim on Windows is shipped with win32yank
!
Creating symlink
winget
installs Neovim in Program Files
,
and win32yank.exe
is located in the bin
subfolder.
Use this command to create a symlink in your home folder,
so Neovim can see it.
ln --symbolic /mnt/c/Program\ Files/Neovim/bin/win32yank.exe ~/.local/bin/win32yank.exe
Of course, ~/.local/bin
has to exist
and be in your $PATH
for this to work.