Note: Copy/Paste for Neovim in WSL

August 23, 2023
vim wsl

If you want a seamless copy/paste experience on Neovim in WSL there is a newly recommended method for doing so, without having to install extra software.

Paste the following Lua snippet in your configuration and "+y to yank the selected text into your global register. Similarly, use "+p to paste.

if vim.fn.has "wsl" == 1 then
  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,
  }
end
Clojure on MacOS Faster key repeat on Windows