1 changed files with 21 additions and 19 deletions
@ -1,22 +1,24 @@
|
||||
-- ~/.config/nvim/lua/config/clipboard.lua |
||||
local function osc52_copy(lines) |
||||
local data = table.concat(lines, "\n") |
||||
local b64 = vim.fn.system("base64 -w0", data) |
||||
vim.fn.chansend(vim.v.stderr, "\x1b]52;c;" .. b64 .. "\x07") |
||||
end |
||||
|
||||
-- Only override clipboard when running over SSH. |
||||
-- Locally, let Neovim auto-detect the system clipboard tool (xclip, pbcopy, wl-copy, etc.) |
||||
if vim.env.SSH_TTY then |
||||
local osc52 = require("vim.ui.clipboard.osc52") |
||||
|
||||
vim.g.clipboard = { |
||||
name = "OSC 52", |
||||
name = "OSC 52 (SSH)", |
||||
copy = { |
||||
["+"] = osc52_copy, |
||||
["*"] = osc52_copy, |
||||
["+"] = osc52.copy("+"), |
||||
["*"] = osc52.copy("*"), |
||||
}, |
||||
paste = { |
||||
["+"] = function() |
||||
return vim.split(vim.fn.getreg("+"), "\n") |
||||
end, |
||||
["*"] = function() |
||||
return vim.split(vim.fn.getreg("*"), "\n") |
||||
end, |
||||
-- OSC52 paste reads back from the terminal via an escape sequence response. |
||||
-- If your terminal supports it (Kitty, WezTerm, iTerm2, etc.), use it: |
||||
["+"] = osc52.paste("+"), |
||||
["*"] = osc52.paste("*"), |
||||
}, |
||||
} |
||||
end |
||||
|
||||
-- Always sync unnamed register with the clipboard register |
||||
vim.opt.clipboard = "unnamedplus" |
||||
Loading…
Reference in new issue