neovim / neovim

Vim-fork focused on extensibility and usability
https://neovim.io
Other
81.78k stars 5.6k forks source link

Support OSC 52 remote copy in terminal buffer #20672

Closed tristone13th closed 3 months ago

tristone13th commented 1 year ago

Feature description

OSC52 can let us copy text from a remote (e.g., ssh) machine to the local terminal (e.g., Windows Terminal), however, the terminal buffer in Neovim seems didn't support this feature. The behavior this issue wants to accomplish is to allow us to copy some text in the Neovim terminal, such as by executing the command like printf "\E]52;c;%s\a" in the terminal, and the result is copied to local.

justinmk commented 4 months ago

OSC/DCS are now forwarded to the TermRequest autocmd event. However I think we don't have a default handler for :terminal.

We have a default handler for bg color: https://github.com/neovim/neovim/blob/cf9f002f31c8b4d9d42912a3f45f5d3db4462fd9/runtime/lua/vim/_defaults.lua#L256-L258

farnoy commented 4 months ago

I'm using nvim v0.10.0-dev-b5583ac over SSH, from a Windows 11 & alacritty client, and while :=require('vim.ui.clipboard.osc52').copy('+')({'asd', 'fasd'}) works fine to copy to system clipboard on the client, setting vim.g.clipboard as in the docs doesn't actually work with something like "+yy. Is this a known issue, or should I create a new one for it?

justinmk commented 4 months ago

setting vim.g.clipboard as in the docs doesn't actually work with something like "+yy. Is this a known issue, or should I create a new one for it?

not a known issue, yes please create one. is there an alternative config that works ?

gpanders commented 4 months ago

Can you share exact reproduction steps (including how you are setting vim.g.clipboard)? Setting vim.g.clipboard is exactly what Nvim itself is doing so we know that it should work: https://github.com/neovim/neovim/blob/bb032d952bfc692062fceb764ff2742c5bdd3324/runtime/plugin/osc52.lua#L31-L43

farnoy commented 4 months ago

Weird, I created a minimal repro, then it proceeded to alternate between working and not, in a non-deterministic way. Seems like a problem elsewhere with my systems and not with nvim. I'll experiment with a Linux client too to isolate the fault.

My repro and what I'm doing in my normal config is this:

-- ADD INIT.LUA SETTINGS _NECESSARY_ FOR REPRODUCING THE ISSUE

vim.g.clipboard = {
  name = 'OSC 52',
  copy = {
    ['+'] = require('vim.ui.clipboard.osc52').copy('+'),
    ['*'] = require('vim.ui.clipboard.osc52').copy('*'),
  },
  paste = {
    ['+'] = require('vim.ui.clipboard.osc52').paste('+'),
    ['*'] = require('vim.ui.clipboard.osc52').paste('*'),
  },
}

vim.opt.clipboard:append 'unnamedplus'
gpanders commented 3 months ago

https://github.com/neovim/neovim/pull/29117