0

I am using neovim on archlinux/WSL2, and try to communicate with the Windows clipboard in neovim.

Following the instructions in :h clipboard-wsl, I filled in init.lua with code:

vim.g.clipboard = {
 name = 'WslClipboard',
 copy = {
 ["+"] = 'clip.exe',
 ["*"] = 'clip.exe',
 },
 paste = {
 ["+"] = 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))',
 ["*"] = 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))',
},
 cache_enabled = 0,
 }

But when I try to yank using "+y, I get "Clipboard: No Provider". However running :checkhealth, I get:

Clipboard (optional)
   - OK Clipboard tool found: WslClipboard

If I run echo "hello world" | clip.exe in the terminal, all work fine: I can paste "hello world" in windows side. And so is the powershell.exe ... command.

After I yank something, I can't find the content in '+' register or '*' register, they are just missing in the result of :reg. So I'm inclined to think the clipboard function is not trigerred, then I tried to install xclip, and luckily the problem is solved.

7
  • Are you using Vim or Neovim? Which is the distribution you are using? May 30, 2023 at 6:08
  • I can't reproduce your problem. It seems to work fine for me. Are the clip.exe and powershell.exe command running smooth in WSL? May 30, 2023 at 11:38
  • @VivianDeSmedt I'm using neovim on archlinux@WSL2, and the clip.exe and powershell.exe both work fine in the terminal. It would be nice if you can tell me how to debug and what to look into.
    – Jerry Z
    Jun 1, 2023 at 8:24
  • Something weird is going on. "Clipboard: No Provider" and "Clipboard tool found" are total contradictions. I'm inclined to think you backed into a corner case (a bug that appears rarely). Try reinstalling neovim. Try a newer version; try an older version. Try another wsl distribution. Basically try to reproduce this issue in multiple environments, and don't do any copy-pasting. This is to ensure that the bug is reproducible and isn't contingent on some of your config (that you haven't posted here because it's seemingly irrelevant).
    – 3N4N
    Jun 1, 2023 at 9:49
  • 1
    @VivianDeSmedt It's {'paste': {'*': 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))', '+': 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))'}, 'cache_enabled': 0, 'name': 'WslClipboard', 'copy': {'*': 'clip.exe', '+': 'clip.exe'}}
    – Jerry Z
    Jun 1, 2023 at 13:23

2 Answers 2

1

Well I fix the problem by simply installing xclip. I don't know why, and I used to think that is unneeded because I'm not going to use the clipboard in X11 but the one in Windows.

3
  • Did you also changed the neovim configuration? Jun 1, 2023 at 14:35
  • I have xclip but because I'm in console mode xclip complains about Error: Can't open display: (null). Jun 1, 2023 at 15:00
  • 1
    @VivianDeSmedt No, I didn't change any configuration.
    – Jerry Z
    Jun 2, 2023 at 3:09
0

Try using win32yank its much faster than using powershell and xclip.

Download the win32yank binary here https://github.com/equalsraf/win32yank/releases then copy it to /usr/local/bin dont forget, should be chmod +x win32yank.exe.

After that add this to your neovim config.

    vim.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 = true,
    }

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.