How do I make the active window automatically expand to take up most of the screen?
Answer
:set winheight=999 winminheight=5
Explanation
Setting winheight to a very large number forces Vim to always try to make the focused window as tall as possible. Because Vim must also satisfy winminheight for every other window, the result is a natural "accordion" layout: the active split expands to nearly fill the screen while inactive splits collapse to just a few lines.
How it works
winheight=999— the minimum height Vim will try to give the current window. Since 999 lines is almost always more than the terminal height, Vim gives it all available space.winminheight=5— every other window gets at least 5 lines, enough to see the filename and a few lines of context- Vim recalculates layout every time you move focus to a different window, so the zoom effect is automatic
Add the same pair for width to get zoom in both dimensions:
set winheight=999 winminheight=5
set winwidth=999 winminwidth=15
Example
Before (equal splits):
┌────────────────┐
│ file1.py (10L) │
├────────────────┤
│ file2.py (10L) │
└────────────────┘
After focusing file1.py with winheight=999:
┌────────────────┐
│ │
│ file1.py (18L) │
│ │
├────────────────┤
│ file2.py (2L) │
└────────────────┘
Tips
- This setting persists for the session; toggle it on/off with a mapping if you want to switch between zoom and equal layouts
:wincmd =(or<C-w>=) resets all windows to equal sizes, temporarily overriding the auto-zoom until you move focus again:help 'winheight'for full details