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 winfixbufor:setlocal winfixbufenables 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 nowinfixbufunlocks 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
winfixbufso:cnextupdates the main editing window, not the quickfix window itself - In Lua configs:
vim.wo.winfixbuf = true - Check if active with
:set winfixbuf?