How do I remove duplicate entries from the Vim arglist after adding files multiple times?
Answer
:argdedupe
Explanation
If you build an arglist incrementally (:args, :argadd, glob expansions), duplicates can sneak in and make :argdo workflows slower or confusing. :argdedupe removes repeated file entries while preserving a clean traversal order, so batch edits and reviews run once per file.
How it works
:argdedupe
- Operates on the current argument list
- Removes duplicate file paths from that list
- Leaves you with a canonical set of targets for
:next,:argdo, and related commands
This is especially useful after combining multiple globs or rerunning setup commands in a long editing session.
Example
Imagine your arglist currently includes:
src/a.go src/b.go src/a.go src/c.go src/b.go
After running :argdedupe, it becomes:
src/a.go src/b.go src/c.go
Now :argdo operations execute exactly once per file.
Tips
- Run
:argsbefore and after to inspect the arglist state. - Use this before project-wide substitutions to avoid accidental duplicate writes.