How can I print only arglist files that still contain trailing whitespace before bulk cleanup?
Answer
:argdo if search('\s\+$', 'nw') | echo expand('%') | endif
Explanation
Before running destructive cleanup across many files, it helps to know which files will actually change. This pattern walks the current argument list and prints only filenames that still match trailing whitespace. It is useful when you want a quick audit pass before deciding whether to run a replacement command globally.
How it works
:argdoexecutes the following Ex command once per file in the argument listsearch('\s\+$', 'nw')checks for trailing whitespace without moving the cursor (n) and without wrapping (wis omitted)if ... | echo expand('%') | endifprints the current file path only when a match is found
Because this approach is read-only, you can use it as a safety step in larger refactors. Pair it with quickfix or your shell history to document exactly which files need cleanup.
Example
Given an arglist with three files:
a.py (has trailing spaces)
b.py (clean)
c.py (has trailing spaces)
Running the command prints:
a.py
c.py
Tips
- Follow with
:argdo %s/\s\+$//e | updatewhen you are ready to apply fixes - Build the arglist first (for example,
:args **/*.py) so the audit is scoped