rchome
rchome

Reputation: 2723

Resize splits in Vim automatically across tabs

I use a lot of tabs in my Vim workflow, and each tab may have several splits in them. I recently discovered in Preserving equal sized split view that having this line in my vimrc helps will automatically make my splits equally sized.

autocmd VimResized * wincmd =

However, it only seems to resize the current tab I'm on if I resize the window that Vim is in. For other tabs, the splits are still unequally sized. Is there a way to automatically resize the splits in all tabs when the window size changes?

Upvotes: 4

Views: 629

Answers (1)

filbranden
filbranden

Reputation: 8898

You can use the :tabdo command to execute the sequence In all existing tabs. This already gets the job done:

autocmd VimResized * tabdo wincmd =

There's one possibly undesirable side effect though, it will end the command on the last tab. You can work around that by saving it and restoring it after the end of the command. It's easier to do so by defining a function.

function! ResizeWindows()
    let savetab = tabpagenr()
    tabdo wincmd =
    execute 'tabnext' savetab
endfunction
autocmd VimResized * call ResizeWindows()

Upvotes: 4

Related Questions