luawindows-subsystem-for-linuxneovimlua-tablerc

RC script to Lua table


I would like to convert this vimrc script to lua.

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

So far I've done this, but I'm struggling with the string operators:

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

What I'm trying to do here is to set WSL clipboard for neovim. If anyone has a better approach/method, it's welcome too.

I'm following a neovim wiki here and lua guide here.


Solution

  • Seems like I figured it out. For anyone searching for an answer:

    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
    

    Here is the official Neovim's clipboard solution for WSL written in Lua.