Open peterfication opened 2 weeks ago
I think it should be possible to add, just hasn't been done :) I'm not sure I'll have time in the near future so if anyone wants to take a stab at this feel free to :)
So the first problem is that I used a mapping of :Telescope Telescope neoclip<CR>
which results in the problem of "No visual range allowed". If I map <CMD>Telescope neoclip<CR>
, it works just fine.
However, the pasted text is inserted before of after the cursor, but it does not overwrite the visual selection. So I will look into the code to see whether this can be adapted in a reasonable amount of effort.
According to this comment, it might not be possible in neoclip at all, but needs to be handled outside of neoclip.
The problem is that you loose the visual selection as soon as Telescope opens. So one solution could be to write a function that saves the visual selection somewhere and on select of a neoclip entry select the visual range again.
So I made it work with the following:
Visual keymap: <ESC><CMD>Telescope neoclip<CR>
(The <ESC>
is necessary to "save" the visual selection).
Custom neoclip action:
local function visual_paste(opts)
local handlers = require("neoclip.handlers")
handlers.set_registers({ 'z' }, opts.entry)
vim.api.nvim_feedkeys('gv"zp', "n", false)
end
require("neoclip").setup({
-- ...
keys = {
telescope = {
n = {
custom = {
["v"] = visual_paste
},
},
i = {
custom = {
["<c-v>"] = visual_paste
},
},
},
},
})
@AckslD Should I contribute this to the README?
I often select a certain word and want to replace it with a paste. Unfortunately, I can't use neoclip properly yet when doing this because it says "No visual range allowed".
I could fake it with a visual keymap to
d:Telescope neoclip<CR>
, which first deletes the selected word and then opens Neoclip. However, if I cancel, the word will be deleted anyways.Is it somehow possible to add a visual range? Or is it too complex?