How do I prevent Vim from automatically resizing a window when others open or close?
Answer
:set winfixwidth
Explanation
Setting winfixwidth on a window tells Vim not to adjust its width when other windows are created, closed, or resized with <C-w>=. This is essential for keeping sidebar-style panels — like a file explorer or a terminal — at a stable width while the main editing area freely resizes around them.
How it works
:set winfixwidthmarks the current window's width as fixed- Vim will not touch that window's width during layout adjustments (e.g.,
:vsplit,<C-w>=, or closing another vertical split) - The complementary option
winfixheightprotects horizontal height instead :set nowinfixwidthor:setlocal nowinfixwidthremoves the lock
Example
You have a narrow file browser open on the left (20 columns wide) and a main code window on the right. Without winfixwidth, opening a new vertical split redistributes width equally:
Before split: After :vsplit (no winfixwidth):
+------+----------+ +------+------+------+
| tree | code | | tree | code | code |
| 20c | 80c | | 33c | 33c | 33c | ← tree grew!
+------+----------+ +------+------+------+
With winfixwidth set in the tree window:
After :vsplit (with winfixwidth on tree):
+------+------+------+
| tree | code | code |
| 20c | 40c | 40c | ← tree stays fixed
+------+------+------+
Tips
- Set it in a
FileTypeautocommand to apply automatically to file explorer buffers:autocmd FileType netrw setlocal winfixwidth - Pair with
:vertical resize 20to first set the desired width before locking it winfixbuf(Vim 9.0+) additionally prevents the buffer in the window from being changed