How do I append the current filename to a named register from Ex command-line?
Answer
:let @a .= expand('%:t') . "\n"
Explanation
Named registers are not just for yanks and deletes. You can build them programmatically from Ex, which is very useful when assembling reusable snippets, macro input, or ad-hoc file lists. Appending the current filename into a register gives you a lightweight way to accumulate context while hopping through buffers.
How it works
:letassigns values to Vim variables and registers@atargets registera.=appends instead of replacing existing contentsexpand('%:t')resolves the current buffer's tail filename."\n"adds a newline so repeated runs create one filename per line
Example
Run this in each file you want to collect:
:let @a .= expand('%:t') . "\n"
After visiting several buffers, inspect with:
:reg a
Then paste the list anywhere with "ap or execute further transformations against it.
Tips
- Use
%:pinstead of%:tto append full absolute paths - Switch to another register by changing
@ato@b,@c, and so on - Reset before a new collection pass with
:let @a = ''