How do I run a command on every open buffer?
Answer
:bufdo command
Explanation
The :bufdo command executes an Ex command on every buffer in the buffer list. This is the buffer-level equivalent of :windo and :argdo.
How it works
:bufdo commandrunscommandin each buffer:bufdo %s/old/new/gereplaces text across all buffers:bufdo updatesaves all modified buffers
Example
Replace var with const in all open files:
:bufdo %s/var/const/ge | update
Tips
- The
eflag suppresses errors when pattern is not found :bufdo updatesaves only modified buffers (better than:wall):set hiddenis recommended when using:bufdo:argdoand:cfdoare alternatives for specific file sets:windoruns commands only in visible windows