How do I resize Vim windows to exact dimensions?
Answer
:resize N / :vertical resize N
Explanation
The :resize and :vertical resize commands set a window to an exact number of lines or columns. This gives you precise control over window layout beyond the <C-w>+/- incremental resizing.
Exact sizing
:resize 20 " Set current window height to 20 lines
:vertical resize 80 " Set current window width to 80 columns
:resize +5 " Increase height by 5 lines
:resize -5 " Decrease height by 5 lines
:vertical resize +10 " Increase width by 10 columns
Quick keyboard shortcuts
<C-w>+ " Increase height by 1
<C-w>- " Decrease height by 1
<C-w>> " Increase width by 1
<C-w>< " Decrease width by 1
5<C-w>+ " Increase height by 5
10<C-w>> " Increase width by 10
<C-w>= " Equalize all window sizes
<C-w>_ " Maximize current window height
<C-w>| " Maximize current window width
Practical layouts
" Main window on left (100 cols), sidebar on right (40 cols)
:vertical resize 100
" Code on top (large), terminal on bottom (small)
:resize 30
<C-w>j :resize 10
" Equal thirds
<C-w>=
Useful mappings
" Arrow keys to resize windows
nnoremap <Up> :resize +2<CR>
nnoremap <Down> :resize -2<CR>
nnoremap <Left> :vertical resize -2<CR>
nnoremap <Right> :vertical resize +2<CR>
Tips
:resizeaffects height,:vertical resizeaffects width- Use absolute numbers for exact sizing,
+/-for relative adjustments <C-w>=quickly resets all windows to equal sizeswinheightandwinwidthoptions set minimum sizes for the active window- Set
winminheight=0to allow windows to be fully collapsed (showing only the status line)