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

How do I append yanked text to an existing register without overwriting it in Vim?

Answer

"Ay{motion}

Explanation

Using an uppercase register letter with any operator appends to the register instead of replacing it. This lets you collect text from multiple locations across a file into a single register for a combined paste — without the overhead of intermediate buffers or repeated yanking.

How it works

Every named register (az) has a corresponding uppercase alias (AZ). When you prefix an operator with the uppercase version, Vim appends the new text to whatever the register already holds:

  • "Ay{motion} — appends yanked text to register a
  • "Ad{motion} — deletes and appends the deleted text to register a
  • "Ac{motion} — changes text and appends the old content to register a

Start with a fresh register by clearing it: qaq records an empty macro into a, effectively zeroing it out.

Example

Imagine you want to collect three function signatures from different parts of a large file:

" Clear register a first
qaq

" Go to first signature, yank the line, appending to a
"Ayy

" Go to second signature
"Ayy

" Go to third signature
"Ayy

" Paste all three at once
"ap

The result in a is a concatenation of all three yanked lines, ready to paste together.

func Add(a, b int) int
func Sub(a, b int) int
func Mul(a, b int) int

Tips

  • Works with any operator and any motion: "AyiW appends a WORD, "Adip appends a paragraph after deleting it
  • Use "ad (lowercase) to start a fresh collection — the first delete/yank replaces the register, subsequent uppercase appends accumulate
  • :registers a shows the current content of register a so you can verify what has been collected
  • This technique is especially useful when building up a snippet list for documentation or refactoring across a codebase

Next

How do I highlight only the line number of the current line without highlighting the entire line?