How do I make buffer jumps prefer the last-used window that already shows the target buffer?
Answer
:set switchbuf+=uselast
Explanation
When jumps open the target buffer in an unexpected split, context switching gets expensive. :set switchbuf+=uselast changes that behavior so commands that honor switchbuf prefer the last-used window already showing the destination buffer. This is a subtle but high-impact improvement when you work with quickfix lists, tags, and multi-window refactors.
How it works
switchbuf controls where Vim opens or reuses buffers during jump-style commands.
:set switchbuf+=uselastappends theuselaststrategy- With
uselast, Vim prefers the most recently used window that already displays the buffer - This reduces layout churn compared with opening new splits or choosing arbitrary existing windows
You can combine it with other values:
:set switchbuf=useopen,usetab,uselast
That sequence says: reuse an open window first, reuse an open tab if needed, and bias toward the last-used matching window.
Example
Suppose main.py is visible in two windows: one narrow diagnostics split and one main editing split. You jump from quickfix to a main.py entry.
Without uselast, Vim may pick the less convenient window. With uselast, it prefers the window you were actively using most recently, preserving editing flow.
Tips
- Use
:set switchbuf?to inspect your active strategy - Add this in filetype or project-local config if different projects need different jump behavior
- Pair with
:help :cnext/ tag jumps to make navigation feel consistent across workflows