ojroques / nvim-osc52

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

auto copy contents from register not working as expected #23

Closed marsjane closed 1 year ago

marsjane commented 1 year ago

I used the config provided in the readme

function copy()
  if vim.v.event.operator == 'y' and vim.v.event.regname == '+' then
    require('osc52').copy_register('+')
  end
end

vim.api.nvim_create_autocmd('TextYankPost', {callback = copy})

In this case, if I use "+yy to yank, the contents will be yanked to the system clipboard and I can paste it anywhere, but if I directly use yy to yank, nothing will be copied to the system clipboard, I used the :reg to checked the register, the contents is in the + register, why it is not copied to system clipboard?

ojroques commented 1 year ago

yy uses the unnamed register. Try with:

function copy()
  if vim.v.event.operator == 'y' and (vim.v.event.regname == '' or vim.v.event.regname == '+') then
    require('osc52').copy_register('+')
  end
end
marsjane commented 1 year ago

wow it works, thanks!! Btw, I need to use local function in my case.