How to efficiently paste over multiple lines again and again with the same text in Vim?

To make your workflow work as expected, you need to paste from the previous yank register "0, rather than the default register.

So use Vy (or yy, which is the same) to yank the first line as before, then position the cursor over the line you want to replace, and do

V"0p

this replaces the current line with the previously yanked text, but doesn't overwrite the yanked text. I hope I understood you correctly!

EDIT 1: repeating using a macro

I was surprised that this operation isn't repeatable using ., but this is presumably due to the use of visual mode. To repeat the operation using a macro, do this:

qqV"0pq

The macro can then be repeated by pressing @q or @@.

EDIT 2: repeating using .

Here's an attempt at making it repeatable using . by not using visual mode. After yanking the stamp line and moving the cursor, do this:

"_S<c-r>0<delete>

which uses the insert mode <c-r> command to insert the contents of register 0. Note that the <delete> is necessary because the stamp line contained a carriage return. If it did not (i.e. yanking using y$ rather than yy) the <delete> could be omitted.

Tags:

Vim