0

According to :h clipboard-wsl in neovim,

For Windows WSL, try this g:clipboard definition:

let 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,
    \ }

I have my wsl.conf not to append $PATH, so I modified that so pathes in the script will be full path. My powershell has a space in its path so I'm trying to escape it, but never succeed.

For example,

  • Double-quoting the whole path like '"/mnt/c/Program Files/PowerShell/7/pwsh.exe" ...' results in
    E475: Invalid value for argument cmd: '"/mnt/c/Program' is not executable error.
  • Quoting just the space like '/mnt/c/Program" "Files/PowerShell/7/pwsh.exe ...' results in almost same error except "/mnt/c/Program is /mnt/c/Program".
  • Escaping the space with \ like '/mnt/c/Program\ Files/PowerShell/7/pwsh.exe ...' causes similar error too.

Why does it happen? How can I avoid it?

5
  • This part of neovim source code is quite tricky. You might think (I certainly did) that nvim will execute a shell command, but that's not the case. I forgot exactly what the implementation is, so can't help you on escaping-slashes. But I am using a shell script to avoid this kind of situation. And invoking pwsh to use clipboard will be unnecessarily time-consuming (try it yourself and see how long it takes to execute a command through a new instance of pwsh). It's far easier to use paste directly.
    – 3N4N
    Dec 26, 2022 at 10:17
  • Here is my g:clipboard dictionary: sourcehut link. And here is the 'wslyank' script: sourcehut link.
    – 3N4N
    Dec 26, 2022 at 10:19
  • In my environment there is no /mnt/c/Windows/System32/paste.exe. How can I get it?
    – Dugesia7
    Dec 26, 2022 at 10:46
  • 1
    Good question. I thought it came with Windows by default, but, after searching the internet, apparently not. I don't know how it came in my Windows 11. I didn't install anything. BTW, neovim ships 'win32yank' with it as well. Check in the bin/ folder. You can use that instead of 'clip.exe' and 'paste.exe'.
    – 3N4N
    Dec 26, 2022 at 10:55
  • I built neovim by myself so I got win32yank.exe from github. It worked, thank you!
    – Dugesia7
    Dec 27, 2022 at 10:49

1 Answer 1

1
  1. Split command by hand, e.g. '+': ['/full path to/pwsh', '-c', 'args']

  2. Learn how to create symlinks and have no worries ever

  3. Drop pwsh as it's too slow. Just anything else will do better.

1
  • I confirmed that first one worked (though I don't know why). But I'll use another mean for speed reason. Thank you!
    – Dugesia7
    Dec 27, 2022 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.