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

How do I run a window-local setting command in every open window?

Answer

:windo setlocal colorcolumn=+1

Explanation

When a setting is window-local, changing it once does not affect your other splits. :windo lets you execute a command in every window in the current tab page, which is faster and less error-prone than repeating the same :setlocal manually. This is especially useful during focused editing sessions where you want consistent visual guidance across many splits.

How it works

  • :windo iterates over each window in the current tab
  • setlocal ensures only the current window's local option is changed
  • colorcolumn=+1 sets the guide one column past textwidth

Because colorcolumn is local to each window, this command gives you a consistent rule without changing global defaults.

Example

Suppose you have three splits open: code, tests, and docs. Before running the command, only one split has a margin guide.

:windo setlocal colorcolumn=+1

After running it, all three windows show the same column guide relative to each buffer's textwidth.

Before: [code: on] [tests: off] [docs: off]
After:  [code: on] [tests: on]  [docs: on]

Tips

  • Use the same pattern for other local options: :windo setlocal cursorline or :windo setlocal number.
  • To apply globally instead, use :set instead of setlocal.
  • Pair with :tabdo when you need the change in every tab page, not just the current one.

Next

How do I convert all hexadecimal numbers to decimal in Vim?