Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

解决 WSL2 下面 nvim 无法复制内容共享给windows粘贴板的问题 #52

Open
zevorn opened this issue Dec 29, 2024 · 0 comments

Comments

@zevorn
Copy link

zevorn commented Dec 29, 2024

我使用的环境是 win11 + wsl2 + arch,解决办法是借助 win32yank.exe ,流程如下:

由于 WSL 可以直接执行 exe 文件,我们将 win32yank.exe 下载到 arch 里面即可:

curl -sLo/tmp/win32yank.zip https://github.com/equalsraf/win32yank/releases/download/v0.1.1/win32yank-x64.zip
unzip -p /tmp/win32yank.zip win32yank.exe > /tmp/win32yank.exe
sudo mv /tmp/win32yank.exe /usr/local/bin/
sudo rm -rf /tmp/win32yank.zip

这里可以简单测试一下:

# Set the clipboard

    echo "hello brave new world!" | win32yank.exe -i
    
# Get the clipboard.

    win32yank -o

如果输出 hello brave new world! ,则证明可以正常工作。

下一步修改 nvim 的配置文件 ~/.config/nvim/lua/archvim/options.lua ,插入以下内容:

-- vim.g_printed = ''
-- vim.g_print = function(msg)
--     vim.g_printed = vim.g_printed .. tostring(msg) .. '\n'
-- end
-- vim.g_dump = function()
--     print(vim.g_printed)
-- end

# 放在上面这个注释的后面即可

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

这样正常使用 y,即可复制到系统粘贴板了。

PS: 感谢小彭老师的指导,比心~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant