vimtricks.wiki Concise Vim tricks, one at a time.

How do I save only modified files across the argument list in Vim?

Answer

:argdo update

Explanation

When working through an argument list, many files may remain unchanged. Writing all of them with :argdo write can trigger unnecessary file timestamp churn, external watchers, and avoidable merge noise. :argdo update keeps the batch write pass safe by only writing buffers that are actually modified.

How it works

  • :argdo executes an Ex command for every file in the current argument list
  • update writes the buffer only if it has unsaved changes
  • Unmodified files are skipped automatically
:argdo update

This command is especially useful as the last step after a multi-file refactor where some files matched and others did not.

Example

Suppose your argument list contains three files:

api/user.go
api/team.go
api/audit.go

You run a substitution across all files, but only user.go and audit.go changed. Running :argdo update writes only those two files; team.go is left untouched.

Tips

Pair this with :args or :argadd to control scope precisely. For safer refactors, use :argdo %s/old/new/ge | update so non-matching files do not error and only modified buffers are written.

Next

How do I prepend a custom persistent undo directory while keeping existing undodir paths in Vim?