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 (a–z) has a corresponding uppercase alias (A–Z). 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 registera"Ad{motion}— deletes and appends the deleted text to registera"Ac{motion}— changes text and appends the old content to registera
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:
"AyiWappends a WORD,"Adipappends 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 ashows the current content of registeraso 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