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

How do I append text to a named register programmatically without re-recording a macro?

Answer

:let @a .= "text"

Explanation

Vim registers are just strings, and you can read and write them directly using the :let command. The .= string concatenation operator lets you append to a register's current value without overwriting it. This is far more flexible than the uppercase-register append trick ("Ayy) and is essential when you need to build up register content algorithmically or add a newline separator between yanked chunks.

How it works

  • :let @a = "hello" — set register a to the string hello
  • :let @a .= " world" — append world to register a, making it hello world
  • :let @a .= "\n" — append a newline character (useful before pasting multi-line content)
  • :echo @a — inspect register contents at any time

The .= operator is Vimscript's in-place string concatenation assignment, equivalent to @a = @a . " world".

Example

Suppose you want to build a register containing a multi-line snippet:

:let @a = "#!/usr/bin/env python3"
:let @a .= "\n"
:let @a .= "import sys"

Then "ap pastes:

#!/usr/bin/env python3
import sys

Tips

  • Clear a register first: :let @a = ""
  • Combine with :redir: capture command output then manipulate it with :let @a .=
  • Use :let @+ .= @a to append a named register into the system clipboard
  • Works for any register: @" (unnamed), @+ (clipboard), @/ (search pattern)
  • :put a inserts register contents onto a new line, while "ap pastes at the cursor

Next

How do I see a summary of all previous quickfix lists from my current session and navigate between them?