ojroques / nvim-osc52

A Neovim plugin to copy text through SSH with OSC52
BSD 2-Clause "Simplified" License
355 stars 11 forks source link

Yank behavior on a remote machine: `yy` does not yank, but `"*yy` yanks #21

Closed redstreet closed 1 year ago

redstreet commented 1 year ago

Here is a strange problem I could use help with from the good folks here. I'm using nvim-osc52 with nvim 0.7.2.

Note that if I :set clipboard=unnamed, the behavior changes: yy works on the remote, but cW also copies to the clipboard (on both local and remote), which is not what I want.

Any idea at all what this could be or even how I could debug it? Thanks much in advance!

redstreet commented 1 year ago

It looks like yy on the local machine is being provided by some other mechanism, and not osc52. If I uninstall the nvim-osc52 plugin, local copy-to-clipboard-on-yy still continues to work.

Perhaps nvim can directly access the local machine's clipboard somehow, and yy yanks into such a clipboard? Pointers as to what exactly is happening and what the relevant nvim settings are would be most appreciated :). :set clipboard doesn't seem to be relevant. Thank you!

ojroques commented 1 year ago

Hello! Could you provide your Neovim config?

redstreet commented 1 year ago

Great question. That made me hunt down all the nested .vim files I've collected over the years, where I found this little gem:

" WSL yank support
let s:clip = '/mnt/c/Windows/System32/clip.exe'
if executable(s:clip)                                                                                                               
     augroup WSLYank
        autocmd!
        autocmd TextYankPost * if v:event.operator ==# 'y' | call system(s:clip, @0) | endif
    augroup END
endif

Given the clip.exe, that explains why the yank-to-clipboard was working locally but not remotely.

For anyone who is interested, I removed it and replaced it with the following so that behavior works from anywhere now via nvim-osc52:

-- yy, yw, yiW, y<motion> will yank to system clipboard. cw or dw won't
api.nvim_create_autocmd("TextYankPost", {
  callback = function()
    if vim.v.event.operator == 'y' and vim.v.event.regname == '' then
      require('osc52').copy_register('0')
      vim.highlight.on_yank{higroup="IncSearch", timeout=100}
    end
  end
})

Apologies for wasting your time, and thanks a ton for replying and setting me on the right direction. And thanks a ton for writing and sharing nvim-osc52!

ojroques commented 1 year ago

Good to know it works now !