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
:windoiterates over each window in the current tabsetlocalensures only the current window's local option is changedcolorcolumn=+1sets the guide one column pasttextwidth
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 cursorlineor:windo setlocal number. - To apply globally instead, use
:setinstead ofsetlocal. - Pair with
:tabdowhen you need the change in every tab page, not just the current one.