Is there an option to apply a setting in all tabs and windows, e.g. apply :set number to all open tabs?


Yes, there is! You can accomplish this with :tabdo and :windo. For your case specifically:

:tabdo windo set number

See :help :tabdo and :help :windo for more information.

  • 5
    :tabdo is not sufficient. :help :tabdo says that it operates in the current window of each tab page. To execute a command in all windows in all tabs you'll need :tabdo windo set number. – garyjohn Apr 12 '17 at 0:13
  • Fair point! I'll update. – Tumbler41 Apr 12 '17 at 1:42

:tabdo windo set number gets the job done, but I don't really like it since it actually switches to each tab and window before running the command. After it finishes running, you'll end up on the last window of the last tab.

I think this is a cleaner way to set options in all windows without changing the current tab and window:

function! s:set_all(option, val, ...) abort
  let val = eval(a:val)

  for t in range(1, tabpagenr('$'))
    for w in range(1, tabpagewinnr(t, '$'))
      if gettabwinvar(t, w, '&buftype') !=# ''
      call settabwinvar(t, w, '&'.a:option, val)

command! -complete=option -nargs=+ SetAll call s:set_all(<f-args>)

Running :SetAll number 1 will enable the number column in all windows, except for the ones that have buftype set, such as help windows.

This is the same as running: :tabdo windo let &number = 1. So, the second argument needs to be an assignable expression. Instead of :set filetype=ini, it would be :SetAll filetype "ini".

  • 1
    I'll also add (beside changing the current tab/window) that :tabdo windo may trigger autocommands, and slow down the option settings. While Tommy A's solution cannot be used out-of-the-box, it's the one to prefer in plugins. – Luc Hermitte Apr 12 '17 at 8:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.