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

How do I run the same Ex command in every open tab page at once?

Answer

:tabdo

Explanation

The :tabdo {cmd} command executes an Ex command in each open tab page sequentially, visiting every tab and running the command there. This is the tab-page equivalent of :bufdo (all buffers) or :windo (all windows in the current tab). It is particularly useful when you have multiple files open in separate tabs and want to apply a change — like a substitution, a settings toggle, or a file write — across all of them in one shot.

How it works

  • :tabdo {cmd} — visits each tab page and runs {cmd} in the active window of that tab
  • Vim moves to each tab in order, executes the command, then moves to the next
  • After completion, Vim returns to the last tab visited
  • If a command fails in a tab, :tabdo stops unless you use :silent! to suppress errors

Example

Replace all occurrences of oldname with newname across every open tab:

:tabdo %s/oldname/newname/ge

The e flag suppresses the "no match" error for tabs where the pattern does not appear.

Write all modified files across all tabs:

:tabdo update

This is equivalent to visiting each tab and typing :update (write only if modified).

Tips

  • Use :tabdo set {option} to apply a setting to all tabs at once
  • Chain with silent! to skip errors: :tabdo silent! %s/foo/bar/g
  • :windo runs in all windows of the current tab; :tabdo covers all tabs
  • :tabdo windo diffthis — run diffthis in every window of every tab (nested iteration)

Next

How do I toggle all folding on and off globally with a single keystroke?