How do I automatically equalize window sizes when the terminal is resized?
Answer
:autocmd WinResized * wincmd =
Explanation
When you resize your terminal window, Vim's split layout can become unbalanced. The WinResized event (or VimResized in older Vim) fires whenever the terminal size changes, letting you automatically equalize windows to maintain a clean layout.
How it works
autocmd VimResized *— triggers when the terminal/GUI is resizedwincmd =— equalizes all window sizes- The
*matches all files (the autocmd applies globally) - Add to vimrc for permanent effect
Example
" Auto-equalize on terminal resize
autocmd VimResized * wincmd =
" Or with an augroup for clean management
augroup AutoResize
autocmd!
autocmd VimResized * wincmd =
augroup END
Before resize: windows are equal
Terminal resized: windows become unequal
Autocmd fires: windows are equalized again
Tips
- Use
VimResizedfor Vim,WinResizedfor Neovim (Neovim added this in 0.9) - Combine with
winfixheight/winfixwidthto protect specific windows from equalization wincmd =is equivalent to pressing<C-w>=- For tmux users, this is essential when panes are resized