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

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 winfixwidth marks 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 winfixheight protects horizontal height instead
  • :set nowinfixwidth or :setlocal nowinfixwidth removes 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 FileType autocommand to apply automatically to file explorer buffers: autocmd FileType netrw setlocal winfixwidth
  • Pair with :vertical resize 20 to first set the desired width before locking it
  • winfixbuf (Vim 9.0+) additionally prevents the buffer in the window from being changed

Next

How do I create new files and directories directly inside Vim's built-in file browser without leaving Vim?