vimtricks.wiki Concise Vim tricks, one at a time.

How do I append multiple yanks into one named register and paste them as one block?

Answer

"ayyj"Ayyk"ap

Explanation

Named registers are much more powerful when you treat them as accumulators instead of one-shot clipboards. This trick yanks one line into register a, appends another line into the same register using uppercase A, then pastes the combined result in a single put. It is useful when assembling snippets from different places before inserting the final block.

How it works

  • "ayy yanks the current line into register a
  • j moves to the next line
  • "Ayy appends this line to register a (uppercase register name means append)
  • k returns to the original insertion point
  • "ap puts the entire accumulated register content after the current line

Example

Given:

alpha
beta

Press:

"ayyj"Ayyk"ap

Result:

alpha
alpha
beta
beta

The inserted pair comes from one combined register payload, not two separate puts.

Tips

  • Use :reg a to inspect the register before putting
  • Clear a register with :let @a='' when building a fresh block
  • This pattern scales: append from many locations, then put once where you need it

Next

How do I move the cursor just after each search match instead of at match start?