OSC52: My Cut & Paste Journey
In the olden days with X11, you could just do x11-forwarding in SSH and remote cut and paste would
work. Now with Wayland, this is all broken and supposedly “there are better ways of doing it”. One
of those is
OSC52
support in terminals, but not in VTE based ones, like
Tilix, which is was my default terminal.
(See https://gitlab.gnome.org/GNOME/vte/-/issues/2495 for the 5(!) year old bug).
So I wanted this to work, which meant changing terminal and configuring Neovim - where the latter was way more complex, hard to debug and reason about.
Foot Terminal⌗
Foot is available in Debian/Ubuntu, and looked like a nice alternative. However it doesn’t register itself as a x-terminal-emulator alternative, which can be fixed with:
sudo update-alternatives --install /usr/bin/x-terminal-emulator x-terminal-emulator /usr/bin/foot 100
And then:
sudo update-alternatives --config x-terminal-emulator
To select foot. Then configure it to your liking. Because it’s not a GTK-based terminal I’ve mostly disabled any decorations, only a border, a tiny menu bar and hiding the buttons.
[csd]
border-width=2
border-color=ff404040
color=ff404040
size=12
button-width=0
Neovim⌗
In Neovim (0.9.5, 0.10 has builtin support… no idea if the following will then need to be updated – again):
With your plugin manager, have ojroques/nvim-osc52 included and add the following Lua config:
require('osc52').setup {
max_length = 0,
silent = false,
trim = true,
tmux_passthrough = false,
}
local function copy(lines, _)
require('osc52').copy(table.concat(lines, '\n'))
end
local function paste()
return {vim.fn.split(vim.fn.getreg(''), '\n'), vim.fn.getregtype('')}
end
vim.g.clipboard = {
name = 'osc52',
copy = {['+'] = copy, ['*'] = copy},
paste = {['+'] = paste, ['*'] = paste},
}
Next set set clipboard=unnamed
.
This has the effect that y and p use the register + or * (dunno - it works). The silent=false
gives me
some feedback this OSC52 stuff is working.
All the other things that you can find didn’t work for, did nothing, or I needed to type “+p and “+y like a farmer to paste and copy.
Anyway, the above works for me, for now.