3

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.

Rob Luca
  • 153
  • 10

1 Answers1

4

This one is working for me:

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

To be a bit shorter:

:noremap <silent> <expr> p @" != "" ? 'pq"q' : ""
yolenoyer
  • 8,797
  • 2
  • 27
  • 61
  • Strange, both are working for me; i often use `qXq` to empty any X reg, and it's working with the `@"` reg as well (I discovered this by answering your question)... nervertheless, it's not a problem if the 1st one works! – yolenoyer Jun 20 '16 at 09:10
  • Checked that it indeed works when pasted into Vim, but not when put into my plugin and run that way – Rob Luca Jun 20 '16 at 10:11