How do I append the current line to a register from command line without using yank?
Answer
:let @a .= getline('.') . "\n"
Explanation
Named registers are usually filled with yanks and deletes, but they are also plain variables you can edit with Vimscript. This command appends the current line to register a without changing cursor position, visual state, or operator workflow. It is useful when you are collecting snippets from different places and want to build one reusable payload for later "ap paste or macro input.
How it works
:letassigns or updates a Vim variable-like target.@areferences registera..=appends to the existing register content instead of replacing it.getline('.')returns the current line text.. "\n"adds a newline so repeated appends remain line-separated.
Example
Suppose your cursor visits these lines one by one:
alpha
beta
gamma
Run on each line:
:let @a .= getline('.') . "\n"
After three runs, register a contains:
alpha
beta
gamma
Now paste it anywhere with "ap.
Tips
- Start clean with
:let @a = ''before collecting. - Switch to another register (
@b,@c) to keep separate clip sets for different tasks.