yanky.nvim icon indicating copy to clipboard operation
yanky.nvim copied to clipboard

nitpick about naming and doc around YankyPutBefore/After

Open unphased opened this issue 1 year ago • 1 comments

I'm interested in flipping around the visual mode mappings of p and P, while using yanky, and the use of this simple remap:

-- stop visual paste from clobbering vim yank register
vim.api.nvim_set_keymap('x', 'p', 'P', { silent = true })
-- allow original p behavior with P
vim.api.nvim_set_keymap('x', 'P', 'p', { silent = true })

is prevented with a standard Yanky.nvim config, because of infinite map recursion. We cannot use nonrecursive maps here if we want to preserve yanky's functionality.

The solution of course would be to do

vim.keymap.set({"n"}, "p", "<Plug>(YankyPutAfter)")
vim.keymap.set({"n"}, "P", "<Plug>(YankyPutBefore)")

vim.keymap.set({"x"}, "P", "<Plug>(YankyPutAfter)")
vim.keymap.set({"x"}, "p", "<Plug>(YankyPutBefore)")

instead of

vim.keymap.set({"n","x"}, "p", "<Plug>(YankyPutAfter)")
vim.keymap.set({"n","x"}, "P", "<Plug>(YankyPutBefore)")

The issue I'm pointing out is that in visual mode p doesn't really paste before, nor does P paste after. In both cases they paste to replace the visual selection, and the only thing the P variant does differently (which is important to me) is to not clobber the unnamed register. So what I am saying is that this naming is a bit sloppy and it means without a lot of commenting my configuration looks pretty confusing.

It has unfortunate implications on method naming. Maybe instead of After/Before we have to name them as P and CapitalP or something.

unphased avatar Jan 19 '24 10:01 unphased

Hi @unphased !

Thanks for your interesting feedback. Naming comes from documentation :

*p* *put* *E353* *E1240*
["x]p			Put the text [from register x] after the cursor
			[count] times.

							*P*
["x]P			Put the text [from register x] before the cursor
			[count] times.

But you're right, the behavior in visual mode is different and maybe I should name it another way, I keep this opent and I will think about it.

gbprod avatar Jan 22 '24 08:01 gbprod