I would like to remap all paste commands to take these special actions before pasting the system clipboard "+
register:
if the register is not
"+
, paste according to default behaviourotherwise:
if mode is visual line, make the contents of the register linewise, then paste
else if mode is visual characterwise, past like normal (characterwise)
else if mode is visual block mode, make the contents of the register blockwise, then paste
else if mode is normal mode, then
- if the contents of the "+ register contain a newline character, make the register linewise,
- otherwise leave it characterwise, then paste
I can achieve the outputs required for some of these steps:
if the register is
"+
, thenif
vim.fn.mode() == 'V'
thensetreg('+', getreg('+'), 'V')
then paste...
...
if
vim.fn.mode() == 'n'
then- if
vim.fn.getreg('+'):find('\n')
thensetreg('+', getreg('+'), 'V')
then paste - else paste
- if
I would like to do this pre-processing on the "+
register for all of the pasting commands, p
, gp
, P
, gP
, etc. I'm not sure how to hook all of those at the same time.
There might be an alternative solution too, I could use vim.cmd.put
instead of setreg(..., 'V')
, but I'm not sure how to put characterwise.