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 line and paste not working with osc52 #4

Closed desilinguist closed 2 years ago

desilinguist commented 2 years ago

Thank you for making a great plugin! It's so great to be able to copy text even over an ssh session!

However, after setting up the plugin, I have noticed that my usual workflow of copying and pasting lines (yy and p) no longer works. I get the error:

E353: Nothing in register "

I have set the following in my config:

vim.opt.clipboard = "unnamedplus"

local status_ok, osc52 = pcall(require, "osc52")
if not status_ok then
    return
end

osc52.setup({
    max_length = 0, -- Maximum length of selection (0 for no limit)
    silent = false, -- Disable message on successful copy
    trim = false, -- Trim text before copy
})

-- set this plugin as the clipboard provider
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 },
}

Is there anything I can do to re-enable my copy-line-and-paste workflow? I am new to Neovim so apologies if I am missing something obvious.

desilinguist commented 2 years ago

Something I just noticed: yy does copy because I see the message from osc52 when I do it. It's just the paste with p that doesn't work.

ojroques commented 2 years ago

When you set vim.opt.clipboard = "unnamedplus", you instruct Neovim to put all your yanked text into the + register, which in turn calls the copy() function with the given text. But Neovim still puts the text into your unnamed register " as well. So when you copy text inside Neovim then use p, it should work fine. Did you remap y or yy in your config?

Or did you mean copying text from outside Neovim and pasting inside with p? Unfortunately this case is not supported by most terminal emulators, because letting applications read the clipboard is a security issue. In that case I suggest you use the plugin only to copy, and use your default clipboard provider for pasting. So if you want to copy with <leader>c:

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

Also note that if you don't change any of the default options, you don't need to call setup().

ojroques commented 2 years ago

I've updated the README to address your question, but you can re-open this issue if you still have problems.

desilinguist commented 2 years ago

I was actually referring to text copied from inside neovim and pasting inside neovim. I already use Kitty's keybinding to paste from external applications. Thanks for suggesting that there may be a conflicting remap ... I removed whichkey from my plugin list and yy+p works again! So, whichkey must be remapping it somehow.

desilinguist commented 2 years ago

I think this issue may be related: https://github.com/folke/which-key.nvim/issues/202

desilinguist commented 2 years ago

Yes, indeed. If I fix my local copy of whichkey with the fix suggested in the above issue, yy+p within neovim works fine and so does the integration with the system clipboard. Thanks again for your help!

ojroques commented 2 years ago

Good to know! Glad that your problem is resolved.