Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSC52 very slow in Windows Terminal (workaround provided) #28611

Closed
tgbrooks opened this issue May 2, 2024 · 3 comments
Closed

OSC52 very slow in Windows Terminal (workaround provided) #28611

tgbrooks opened this issue May 2, 2024 · 3 comments
Labels
bug issues reporting wrong behavior clipboard clipboard, paste has:workaround issue is not fixed but can be circumvented until then platform:windows

Comments

@tgbrooks
Copy link

tgbrooks commented May 2, 2024

Problem

Windows Terminal supports OSC52-base copying but not pasting (for security reasons). Using the new OSC52 support in nvim 0.10 works in Windows Terminal however it is very slow (over 10 seconds). The apparent cause of this is that yanking actually first attempts a paste, which isn't supported and so times out, and only afterwards performs the copy.

Therefore, there is a simple way to resolve this problem for users. Instead of the currently recommended configuration to force OSC52 to be used, instead do the following which makes pasting a no-op (since it wouldn't work anyway):

function no_paste(reg)
    return function(lines)
        -- Do nothing! We can't paste with OSC52
    end
end

vim.g.clipboard = {
    name = "OSC 52",
    copy = {
         ["+"] = require("vim.ui.clipboard.osc52").copy("+"),
         ["*"] = require("vim.ui.clipboard.osc52").copy("*"),
    },
    paste = {
        ["+"] = no_paste("+"), -- Pasting disabled
        ["*"] = no_paste("*"), -- Pasting disabled
    }
}

After doing this, copying is immediate. This seems counter intuitive and I don't understand why the paste function is called when yanking (it appears to be called twice: if you replace my no_paste function with something that prints out, you'll see it).

Presumably, this work around would help any other terminal that supports OSC52 copying but not pasting, apparently including wezterm/alacritty, but I have not tested. See also this discussion: #28010 I have also seen this problem mentioned elsewhere.

Steps to reproduce

Using Windows Terminal, ssh to a machine with neovim 0.10. (Or any other situation where OSC52 is used.) Run nvim and yank a line of text, "+yy. Neovim then hangs for a second and eventually displays a message that it timed out waiting for a response from the terminal.

Expected behavior

Yanking to clipboard should be instantaneous even if paste is not available.

Neovim version (nvim -v)

NVIM v0.10.0-dev

Vim (not Nvim) behaves the same?

No

Operating system/version

Windows 11 (Terminal) / Linux (nvim)

Terminal name/version

Windows Terminal Version: 1.19.10821.0

$TERM environment variable

xterm-256color

Installation

build from repo

@tgbrooks tgbrooks added the bug issues reporting wrong behavior label May 2, 2024
@zeertzjq zeertzjq added platform:windows clipboard clipboard, paste has:workaround issue is not fixed but can be circumvented until then labels May 2, 2024
@justinmk justinmk added this to the 0.11 milestone May 3, 2024
@justinmk
Copy link
Member

justinmk commented May 3, 2024

This seems counter intuitive and I don't understand why the paste function is called when yanking

Hmm. And this happens with nvim --clean ?

@tgbrooks
Copy link
Author

tgbrooks commented May 3, 2024

No, it doesn't! Apologies for not checking that before submitting. Must be something in LazyVim then.

@tgbrooks tgbrooks closed this as completed May 3, 2024
@wookayin wookayin removed this from the 0.11 milestone May 4, 2024
@tgbrooks
Copy link
Author

tgbrooks commented May 7, 2024

In case anyone ends up here with the same problem, the culprit appears to be the which-key plugin. This displays the contents of various registers when you type ". But that was triggering the OSC52 paste functionality and hanging everything until the paste timed out, even if you only wanted to yank/copy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issues reporting wrong behavior clipboard clipboard, paste has:workaround issue is not fixed but can be circumvented until then platform:windows
Projects
None yet
Development

No branches or pull requests

4 participants