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

How do I prevent a window from switching to a different buffer in Neovim?

Answer

:set winfixbuf

Explanation

Neovim's winfixbuf option (added in Neovim 0.10) locks a window to its current buffer. Once set, buffer-switching commands like :bnext, :bprev, :buffer, and :e that would normally change which buffer the window displays will instead open a new split. This is invaluable for keeping utility windows — quickfix, terminal, file trees, diffs — pinned while you navigate buffers in your main editing windows.

How it works

  • :set winfixbuf or :setlocal winfixbuf enables it for the current window
  • Commands that try to display a different buffer in the window will open a new window or fail with an error instead
  • :set nowinfixbuf unlocks the window again
  • Certain commands that operate on the buffer list still work: :bdelete, :bwipeout, :quit

Example

" Open a terminal in a bottom split and lock it there
:split
:terminal
:set winfixbuf

" Now <C-w>w + :bnext in main window won't affect the terminal window

Combine with winfixheight to keep the terminal pinned at a fixed height too:

:resize 15
:set winfixheight winfixbuf

Tips

  • Useful with quickfix windows — set winfixbuf so :cnext updates the main editing window, not the quickfix window itself
  • In Lua configs: vim.wo.winfixbuf = true
  • Check if active with :set winfixbuf?

Next

How do I set up a local leader key for file-type-specific mappings that don't conflict with global mappings?