vimtricks.wiki Concise Vim tricks, one at a time.

How do I always maximize the current split window when I switch focus without using plugins?

Answer

:set winwidth=999 winheight=999

Explanation

Setting winwidth=999 and winheight=999 tells Vim to try to make the active window at least 999 columns wide and 999 rows tall whenever it gains focus. Since no terminal is 999 columns wide, this effectively auto-maximizes the focused split every time you switch windows — providing a "golden ratio" experience built into Vim with no plugins needed.

How it works

  • winwidth — minimum width Vim tries to give the current window
  • winheight — minimum height Vim tries to give the current window
  • Values of 999 exceed any practical terminal size, so the focused window gets all available space
  • Other splits are pushed to their minimum size (1 row/column by default)

Every time you switch focus with <C-w>h/j/k/l or click a window, that window expands to fill the available space.

Example

Add to your ~/.vimrc or init.vim:

set winwidth=999
set winheight=999
set winminwidth=5
set winminheight=1

The winminwidth=5 and winminheight=1 settings keep non-focused splits visible as narrow sidebars rather than collapsing entirely.

Tips

  • Use <C-w>= at any time to equalize all windows temporarily
  • Lower values like winwidth=120 winheight=40 give a gentler zoom effect
  • To restore defaults: :set winwidth=20 winheight=1
  • In Neovim, consider pairing with splitkeep=screen to reduce cursor jumping when windows resize

Next

How do I use a Vimscript function to control how the gq operator formats text?