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

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 | update after :bufdo substitutions to save each file
  • Use e flag with :s to suppress "pattern not found" errors
  • :cdo and :ldo work on quickfix/location list entries — great with :vimgrep
  • Combine: :tabdo windo set cursorline sets cursorline everywhere

Next

How do I return to normal mode from absolutely any mode in Vim?