Is there an option to apply a setting in all tabs and windows, e.g. apply
:set number to all open tabs?
: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') !=# '' continue endif call settabwinvar(t, w, '&'.a:option, val) endfor endfor endfunction command! -complete=option -nargs=+ SetAll call s:set_all(<f-args>)
: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".
Another way to keep the current tab:https://vi.stackexchange.com/a/31903
I personally use buffers instead of tabs so I have:
" Toggle line numbers for all buffers/windows/tabs function! ToggleLineNumbers() let current_buffer = bufnr() " tabdo windo bufdo set number! " updated according to the comment from D. Ben Knoble: " tabdo windo set number! " note by goodpen: if a buffer is opened in 2 windows, this may call `:set number!` twice? bufdo set number! execute 'buffer' current_buffer endfunction