How do I inspect only Ex command history so I can quickly rerun a complex command?
Answer
:history :
Explanation
When you work with long substitution pipelines or multi-part Ex commands, digging through all history (:history) adds noise. :history : limits the view to Ex command history only, so you can quickly find the exact command you want to repeat or refine. This is especially useful after a refactor pass where you iterated on several similar commands.
How it works
:historyprints Vim's command histories:narrows that output to the command-line (Ex) history list- Vim shows numbered entries, newest last
- You can rerun an entry with
:{number}or copy parts into the command-line window (q:) for editing
Example
Suppose you recently ran several project-wide substitutions and formatting commands:
:%s/old_api/new_api/ge
:argdo %s/\\<foo\\>/bar/ge | update
:g/^#/d
Now you want to rerun just the second command with a small pattern change. Run:
:history :
Find its index, then execute it again with :{index} and edit as needed.
Tips
- Use
q:when you need full Normal-mode editing over command history - Pair
:history :with:silentin scripts to inspect state without extra redraw noise - If you only need recent entries, combine with history options like
:set history=...to keep a deeper command backlog