Answering the Core Question
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.
Recommended Configuration
- Verify that Neovim was compiled with clipboard support:
:echo has('clipboard')
Expect 1. If 0, OSC52 cannot be used.
- Check the current clipboard setting:
:set clipboard?
After a fresh 0.9 install you should see unnamedplus.
- Enable OSC52 only for trusted hosts. A simple way is to add an
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.
Per‑Host Whitelist Approach
- Pros: Automatic, no manual editing per session.
- Cons: Requires the host name to be reliable and may need adjustment if you use SSH proxies or jump hosts.
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
Verification Checklist
- Does
:set clipboard? show unnamedplus (or unnamedplus,osc52 when on a trusted host)?
- Can you yank text and see it in the system clipboard when on a trusted host?
- Is
osc52 absent when you SSH to an untrusted host?
- Is your terminal emulator capable of OSC52 (e.g., iTerm2, Kitty, Alacritty) and not being wrapped by a multiplexer that blocks the sequence?
- Is
has('clipboard') returning 1?
Ask for Missing Diagnostic Detail
To finalize the recommendation, could you confirm whether your terminal emulator supports OSC52 and whether Neovim reports has('clipboard') == 1?