Neovim 0.9 clipboard default change and OSC52 opt‑in decision
0 reputation · 21 Mar 2023, 01:50 UTC
0 reputation · 21 Mar 2023, 01:50 UTC
Neovim 0.9 changed the clipboard subsystem so that the 'clipboard' option starts empty, requiring an explicit 'set clipboard=unnamedplus' to share the system clipboard. At the same time, OSC52‑based copying over SSH is disabled by default to prevent accidental data leakage. The project is still debating whether OSC52 should remain opt‑in, become opt‑out, or be gated by a per‑host whitelist that balances convenience with safety.
Users who depend on automatic clipboard sharing must decide how to configure OSC52 without exposing copied text to unintended SSH hosts, while also ensuring that existing mappings and plugins that expect unnamedplus continue to work.
Should OSC52 stay opt‑in by default? Would a per‑host whitelist provide a usable middle ground? How can administrators safely enable OSC52 for trusted hosts only?
35275 reputation · 21 Mar 2023, 11:02 UTC
Neovim 0.9 changed the default value of clipboard to unnamedplus, meaning yanks and pastes use the system clipboard automatically. The OSC52 escape‑sequence method is still opt‑in: you must add clipboard+=osc52 to your configuration. Keeping OSC52 opt‑in preserves the safety boundary that the project introduced in 0.9, but a per‑host whitelist can provide a convenient middle ground for administrators who trust specific SSH hosts.
:echo has('clipboard')
Expect 1. If 0, OSC52 cannot be used.
:set clipboard?
After a fresh 0.9 install you should see unnamedplus.
autocmd that tests the remote host name and adjusts clipboard accordingly:" In init.lua or init.vim
if vim.fn.has('clipboard') == 1 then
local host = os.getenv('HOSTNAME') or ""
local trusted = {"trusted‑server‑1", "trusted‑server‑2"}
if vim.tbl_contains(trusted, host) then
vim.opt.clipboard:append('osc52')
else
vim.opt.clipboard:remove('osc52')
end
end
This keeps the default unnamedplus for local sessions and only adds OSC52 when connecting to a host on the whitelist.
If you prefer a more granular approach, you can store the whitelist in a separate file and source it from Neovim:
" ~/.config/nvim/osc52_whitelist.lua
return {"trusted‑server‑1", "trusted‑server‑2"}
" In init.lua
local whitelist = require('osc52_whitelist')
if vim.fn.has('clipboard') == 1 and vim.tbl_contains(whitelist, os.getenv('HOSTNAME')) then
vim.opt.clipboard:append('osc52')
end
:set clipboard? show unnamedplus (or unnamedplus,osc52 when on a trusted host)?osc52 absent when you SSH to an untrusted host?has('clipboard') returning 1?To finalize the recommendation, could you confirm whether your terminal emulator supports OSC52 and whether Neovim reports has('clipboard') == 1?
Use comments to ask for clarification. Post a solution as an answer.
7,010 reputation · 21 Mar 2023, 09:10 UTC
To make sure the osc52 flag stays active even if a plugin later resets clipboard, prepend it with set clipboard^=osc52 (or set clipboard^=unnamedplus for the traditional behavior). The prepend form (^=) adds the flag to the front of the list, so a later assignment like set clipboard=unnamed will not remove it.
Instead of toggling the option, you can define a clipboard provider that checks the SSH environment:
vim.g.clipboard = {
name = 'osc52‑ssh',
copy = {
['+'] = require('vim.ui.clipboard.osc52').copy('+'),
['*'] = require('vim.ui.clipboard.osc52').copy('*'),
},
paste = {
['+'] = require('vim.ui.clipboard.osc52').paste('+'),
['*'] = require('vim.ui.clipboard.osc52').paste('*'),
},
}
-- Enable only when SSH_CLIENT or SSH_CONNECTION is set
if vim.env.SSH_CLIENT or vim.env.SSH_CONNECTION then
vim.opt.clipboard:append('osc52')
else
vim.opt.clipboard:remove('osc52')
end
This keeps the default unnamedplus locally and adds OSC52 only for SSH sessions, without relying on host‑name whitelists.