How do I quickly resize the current window to exactly N lines tall in Vim?
Answer
z{N}<CR>
Explanation
The z{N}<CR> command sets the current window's height to exactly N lines and simultaneously positions the current line at the top of the window. This is a compact alternative to :resize N that works entirely in normal mode without entering the command line.
How it works
z— prefix that triggers a family of view/window manipulation commands{N}— any positive integer (e.g.,10,25) specifying the desired window height in lines<CR>— Enter key, which distinguishes this from otherzcommands likezt(top) orz.(center)
When the screen is split into multiple windows, this command resizes the active window to the specified line count. If the requested height would violate the minimum winheight setting, Vim adjusts accordingly.
Example
Suppose you have three horizontal splits open. To snap the middle window to exactly 15 lines:
:15resize ← one approach (command line)
15z<CR> ← equivalent, from normal mode
This is useful when you want a quick reference pane at a fixed height (e.g., 8z<CR> for a compact quickfix preview) without reaching for the command line.
Tips
<C-w>_maximizes the window height;z{N}<CR>gives you precise control instead<C-w>=re-equalizes all windows after resizing- The command also redraws so the current line sits at the top — combine with
zzafterward if you want the line centered instead - Works with horizontal splits only; use
:vertical resize Nfor vertical split width