ojroques / nvim-osc52

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

difference between using as a clipboard provider vs not? #31

Closed AlJohri closed 6 months ago

AlJohri commented 9 months ago

hi! relatively new to neovim here and trying to understand the difference between the two usages described in the readme

I see one usage looks like this:

vim.keymap.set('n', '<leader>c', require('osc52').copy_operator, {expr = true})
vim.keymap.set('n', '<leader>cc', '<leader>c_', {remap = true})

and the other looks via "clipboard provider" looks like:

local function copy(lines, _)
  require('osc52').copy(table.concat(lines, '\n'))
end

local function paste()
  return {vim.fn.split(vim.fn.getreg(''), '\n'), vim.fn.getregtype('')}
end

vim.g.clipboard = {
  name = 'osc52',
  copy = {['+'] = copy, ['*'] = copy},
  paste = {['+'] = paste, ['*'] = paste},
}

-- Now the '+' register will copy to system clipboard using OSC52
vim.keymap.set('n', '<leader>c', '"+y')
vim.keymap.set('n', '<leader>cc', '"+yy')

Questions:

  1. are these two approaches doing effectively the same thing? 1a. if yes, maybe we can simplify readme to just have one approach? 1b. if no, when would I use the clipboard provider approach as opposed to the keymap + provided functions approach?
  2. can we expose the copy and paste functions within the library itself so users don't need to specify them when using clipboard provider approach? sort of like what will come in neovim 0.10 require('vim.clipboard.osc52').copy?
ojroques commented 9 months ago

Hello!

The two usages are different. The first one creates mapping that calls the plugin directly.

The second one instructs Neovim that to copy the system clipboard, it should use the plugin. Therefore in this scenario, the '+' clipboard (which is used to copy to the system clipboard) will call the plugin instead.

Note that if you are using a recent version of Neovim, the second usage is natively integrated to Neovim and you don't need this plugin to copy through SSH. And this feature is enabled by default is some conditions are met, see :h clipboard-osc52. Then when do "+y, it will copy even via SSH.

ojroques commented 6 months ago

I'm closing this issue but feel free to reopen it if you still have issues.