From e20942db608da333482d7485f123342962e1127a Mon Sep 17 00:00:00 2001 From: sommerfeld Date: Thu, 14 May 2026 11:51:01 +0100 Subject: feat(nvim): wire OSC 52 clipboard provider on SSH sessions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously `clipboard` was set to empty inside SSH sessions on the assumption no clipboard tool would be reachable. That broke yank → host-clipboard on the remote-dev VM. nvim ≥0.10 ships a built-in OSC 52 provider (vim.ui.clipboard.osc52). The terminal emulator (ghostty locally, zellij forwarding inside it) handles the escape sequence and writes to the host's clipboard, so we get yank-to-host without needing wl-copy/xclip on the VM. Paste over OSC 52 is rarely supported by terminals (security), so we wire it but it's effectively a no-op; bracketed paste from the terminal still delivers clipboard contents into the buffer. --- dot_config/nvim/lua/config/options.lua | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/dot_config/nvim/lua/config/options.lua b/dot_config/nvim/lua/config/options.lua index 86529f6..1e8e30f 100644 --- a/dot_config/nvim/lua/config/options.lua +++ b/dot_config/nvim/lua/config/options.lua @@ -48,9 +48,23 @@ vim.opt.completeopt = { "menuone", "noselect", "popup", "fuzzy", "nearest" } opt.scrolloff = 999 -- keep cursor vertically centered opt.sidescrolloff = 5 -- horizontal scroll margin --- Clipboard (deferred to avoid blocking startup on clipboard detection) +-- Clipboard (deferred to avoid blocking startup on clipboard detection). +-- On SSH sessions there is no wl-copy/xclip, so we wire nvim's built-in +-- OSC 52 provider — the terminal emulator (ghostty/zellij) forwards the +-- escape sequence to the host's clipboard. Paste over OSC 52 isn't widely +-- supported by terminals (security), so we only override copy and leave +-- paste as a no-op; bracketed paste still works for inserting clipboard +-- contents into the buffer via the terminal. vim.schedule(function() - opt.clipboard = vim.env.SSH_TTY and "" or "unnamedplus" + if vim.env.SSH_TTY then + local osc52 = require("vim.ui.clipboard.osc52") + vim.g.clipboard = { + name = "OSC 52", + copy = { ["+"] = osc52.copy("+"), ["*"] = osc52.copy("*") }, + paste = { ["+"] = osc52.paste("+"), ["*"] = osc52.paste("*") }, + } + end + opt.clipboard = "unnamedplus" end) opt.mouse = "a" -- enable mouse in all modes -- cgit v1.3.1