How do I capture command output into a register?
Answer
:redir @a | command | redir END
Explanation
The :redir command redirects Vim's command output to a register, file, or variable. This lets you capture and manipulate output programmatically.
How it works
:redir @astarts redirecting output to registera- Run any Ex command that produces output
:redir ENDstops redirecting"appastes the captured output
Example
Capture the output of :marks into register a:
:redir @a
:marks
:redir END
"ap
Tips
:redir >> file.txtappends to a file:redir => variablecaptures to a Vimscript variable- Clear the register first:
:let @a = '' :redir @Aappends to registera(uppercase appends)- Useful for scripting and debugging