vimscriptingtext-editorpasting

Vim "paste once" without update of undo


To implement pasting only once I can use:

noremap <silent> p p:let @"=""<cr>

This clears register after pasting, so that following paste will not work. What will however happen is empty pasting which updates undo. So pressing p 3 times will require 3 undo calls to undo the initial paste.

How to suppress this? I tried something like:

:noremap <expr> @" != "" ? p:let @"="" : <Nop> <cr>

But it doesn't impose any change.


Solution

  • This one is working for me:

    :noremap <silent> <expr> p @" != "" ? 'p:let @"=""<cr>' : ""
    

    To be a bit shorter:

    :noremap <silent> <expr> p @" != "" ? 'pq"q' : ""