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

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 other z commands like zt (top) or z. (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 zz afterward if you want the line centered instead
  • Works with horizontal splits only; use :vertical resize N for vertical split width

Next

How do I paste the contents of a register as a new line below the cursor regardless of the register type in Vim?