feat(clipboard): add OSC 52 clipboard support#25872
Conversation
|
I don't know if this is useful to consider but this is what I have in my config (ref): local function osc52_copy(text)
local text_b64 = encode_base64(text)
local osc = string.format('%s]52;c;%s%s', string.char(0x1b), text_b64, string.char(0x07))
io.stderr:write(osc)
end
vim.api.nvim_create_autocmd('TextYankPost', {
callback = function()
osc52_copy(vim.fn.getreg(vim.v.event.regname))
end
})Which allows osc52 copy to work on top of |
|
I ditched the EDIT: Exposing the module also allows users to do what @lewis6991's snippet does (e.g. copy via OSC 52 in a TextYankPost autocommand). |
c47eef0 to
fe12079
Compare
This is opt-in as not all terminal emulators support OSC 52, so it is up to the user to enable it explicitly.
This ensures that the read stream never overflows termkey's internal buffer. This only happens when a large amount of bytes are pushed into termkey at the same time, which is exactly what happens when we receive a large OSC 52 response.
#3344 mentions:
Can we enable by default if the terminal response indicates that OSC 52 is supported? |
|
I'm not aware of any mechanism to query for OSC 52 support, without actually querying the clipboard itself. But this would be extremely annoying because many terminals prompt the user when an application tries to read from the clipboard, so if we queried for support by just trying to read and checking for a response the user would be prompted every time Nvim started up. |
There was a problem hiding this comment.
Any objection to moving this to vim.ui.* ? That seems like a reasonable place for providers to live: #24164
We could make it opt-out instead of opt-in if a user config is found? |
|
@gpanders Hi, have you noticed frequent neovim freezes when using osc52? |
|
Once Nvim requests the contents of the clipboard with the OSC 52 request there isn't anything we can do until the terminal responds except wait. Do you have a reproducible example where pasting takes a very long time? Are you pasting a lot of data that might take a while to transmit over a slow SSH connection? The long timeout is intentional because some terminal emulators will prompt the user for permission to read from the system clipboard, so we need to wait long enough for the user to respond in those cases. |
|
@alteriks what does |
|
this could be link to |
|
Meanwhile,
|
|
@gpanders Those freezes are happening on local machine. I'm working on single file and after yanking one line I paste it to same file. After that nvim UI is frozen. After some time I can exit vim using
I've never experienced this using kitty. Currently I'm on wayland. So maybe something doesn't work properly and I'm missing some popup. I'll try later with Xorg. I've tried creating config to help you reproduce my problem mkdir ~/.config/nvim_osc52
cat << EOF > ~/.config/nvim_osc52/init.lua
vim.g.clipboard = {
name = "OSC 52",
copy = {
["+"] = require("vim.clipboard.osc52").copy,
["*"] = require("vim.clipboard.osc52").copy,
},
paste = {
["+"] = require("vim.clipboard.osc52").paste,
["*"] = require("vim.clipboard.osc52").paste,
},
}
EOFBut copying/pasting using this minimal config doesn't work over ssh |
For me using With additional mapping I'll have think about it everytime when I'll need to paste some text outside nvim, and most probably I'll have to switch window once again, because I didn't use |
Nvim has supported OSC 52 via tmux for a long time. No additional configuration is needed to use OSC 52 in tmux, as long as you are using tmux 3.2 or later. In fact, we should probably show a warning if the |
Asking on paste is the default behavior of kitty: https://sw.kovidgoyal.net/kitty/conf/#opt-kitty.clipboard_control I cannot reproduce any slowness or delay using kitty (or any other terminal emulator I've tried) on macOS. So maybe this is a Linux specific issue. In any case, please do not comment on this PR with OSC 52 related issues. To report a bug, please create a new issue with clear reproduction steps. |


This is opt-in as not all terminal emulators support OSC 52, so it is up to the user to enable it explicitly.
Fixes: #3344