Created
March 10, 2025 17:33
-
-
Save bigFin/b6c2e562583e74da646b42747674a3ba to your computer and use it in GitHub Desktop.
init.lua chunk to fix nvim clipboard when on ssh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vim.opt.clipboard:append("unnamedplus") | |
-- OSC 52 clipboard provider | |
local function copy(lines, _) | |
local text = table.concat(lines, "\n") | |
vim.fn.chansend(vim.v.stderr, "\x1b]52;c;" .. vim.base64.encode(text) .. "\x07") | |
end | |
local function paste() | |
local content = vim.fn.getreg('"') | |
return vim.split(content, "\n") | |
end | |
-- Set the clipboard provider only when over SSH | |
if vim.env.SSH_TTY then | |
vim.g.clipboard = { | |
name = "OSC 52", | |
copy = { | |
["+"] = copy, | |
["*"] = copy, | |
}, | |
paste = { | |
["+"] = paste, | |
["*"] = paste, | |
}, | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment