Editing files in a terminal editor over SSH, the thing you actually want is for yanking a line to put it on the clipboard of the machine in front of you, not on the clipboard of the server, which has no display and no clipboard.
OSC 52 does this. The editor emits an escape sequence containing base64 text, the terminal emulator receives it and writes it to the local clipboard. It works over SSH, through a multiplexer, with no forwarding and no agent, because it is just bytes in the terminal stream.
The trap is that the specification has a read operation as well, and support for it is close to nonexistent. Terminals that implement copy frequently do not implement paste, because a remote process being able to read your clipboard is a genuine security concern rather than an oversight.
So a configuration with both halves enabled leaves you with working copy and a paste that silently returns nothing. Because the editor believes the clipboard is empty, it can appear to have lost the text you just yanked.
Configure it one-way, with a local fallback for the read side:
-- copy to the local clipboard via OSC 52; read from a register
vim.g.clipboard = {
name = 'osc52',
copy = {
['+'] = require('vim.ui.clipboard.osc52').copy('+'),
['*'] = require('vim.ui.clipboard.osc52').copy('*'),
},
paste = {
['+'] = function() return vim.split(vim.fn.getreg('"'), '\n') end,
['*'] = function() return vim.split(vim.fn.getreg('"'), '\n') end,
},
}
Then paste with the terminal’s own shortcut, which reads the local clipboard directly and does not involve the remote session at all. That is the correct division of labour: the remote side pushes text out, the local side decides what comes in.
Two practical limits. There is a size cap. Long yanks are truncated, and the cap varies by terminal. And inside a multiplexer the sequence has to be passed through, which usually takes one configuration line before anything works at all.
The broader point is that “the protocol supports it” and “the implementations support it” are different claims, and when the gap exists for a security reason, it is not going to close.