0

I would like to remap all paste commands to take these special actions before pasting the system clipboard "+ register:

  1. if the register is not "+, paste according to default behaviour

  2. otherwise:

    1. if mode is visual line, make the contents of the register linewise, then paste

    2. else if mode is visual characterwise, past like normal (characterwise)

    3. else if mode is visual block mode, make the contents of the register blockwise, then paste

    4. else if mode is normal mode, then

      1. if the contents of the "+ register contain a newline character, make the register linewise,
      2. otherwise leave it characterwise, then paste

I can achieve the outputs required for some of these steps:

  1. if the register is "+, then

    1. if vim.fn.mode() == 'V' then setreg('+', getreg('+'), 'V') then paste

    2. ...

    3. ...

    4. if vim.fn.mode() == 'n' then

      1. if vim.fn.getreg('+'):find('\n') then setreg('+', getreg('+'), 'V') then paste
      2. else paste

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.

1
  • :put cannot be characterwise
    – D. Ben Knoble
    Commented Oct 24 at 16:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.