How do I run the same command across all windows, buffers, or tabs?
Answer
:windo set wrap
Explanation
Vim provides iterator commands that execute an Ex command across all windows, buffers, tabs, or argument list files. These are powerful for applying settings, running substitutions, or executing macros across your entire session at once.
How it works
:windo {cmd}— run command in every window:bufdo {cmd}— run command in every buffer:tabdo {cmd}— run command in every tab page:argdo {cmd}— run command on every file in the argument list:cdo {cmd}— run command on every quickfix entry
Example
" Enable wrap in all windows
:windo set wrap
" Search and replace across all buffers
:bufdo %s/old/new/ge | update
" Close all folds in all tabs
:tabdo windo normal zM
Tips
- Add
| updateafter:bufdosubstitutions to save each file - Use
eflag with:sto suppress "pattern not found" errors :cdoand:ldowork on quickfix/location list entries — great with:vimgrep- Combine:
:tabdo windo set cursorlinesets cursorline everywhere