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

How do I prevent a split window from being resized when I open new splits?

Answer

:set winfixwidth winfixheight

Explanation

How it works

When you open new split windows in Vim, the existing windows automatically resize to make room. This can be annoying if you have a window at a specific size that you want to keep stable, such as a file explorer sidebar or a reference file.

Vim provides two window-local options to prevent this:

  • :set winfixwidth locks the current window's width so it will not be resized horizontally when vertical splits are created or closed.
  • :set winfixheight locks the current window's height so it will not be resized vertically when horizontal splits are created or closed.

You can set both together with :set winfixwidth winfixheight to lock the window in both dimensions.

These options only affect automatic resizing. You can still manually resize the window with <C-w>+, <C-w>-, <C-w><, <C-w>>, or the :resize command.

To unlock a window, use :set nowinfixwidth nowinfixheight.

Example

Suppose you have a two-column layout where the left window is a narrow reference panel:

:vsplit reference.txt
:vertical resize 40
:set winfixwidth

Now when you go to the right window and create additional splits with :split or :vsplit, the left reference panel stays at 40 columns instead of being squeezed.

This is particularly useful in combination with :Explore or file tree setups where you want a consistent sidebar width. You can automate this with an autocommand:

autocmd FileType netrw setlocal winfixwidth

This automatically locks the width whenever a Netrw file explorer window opens.

Next

How do you yank a single word into a named register?