How do I make jumps reuse open windows first and fall back to a new tab when needed?
Answer
:set switchbuf=useopen,usetab,newtab
Explanation
When jump commands open files (:tag, quickfix navigation, location list jumps), Vim may split your layout in ways that break flow. The switchbuf option lets you define a smarter reuse policy. Setting useopen,usetab,newtab tells Vim to first reuse an already-visible window, then a tab containing the target buffer, and only create a new tab as a fallback.
How it works
useopenreuses an existing window showing the target buffer when possible.usetaballows jumping to a tab that already has that buffer open.newtabcreates a new tab only when no reusable window/tab exists.
This gives you deterministic navigation behavior across large projects where the same files are revisited from tags, grep results, and quickfix lists.
Example
Configure once:
:set switchbuf=useopen,usetab,newtab
Then run a jump workflow:
:vimgrep /MySymbol/ **/*.go
:copen
:cnext
Instead of spawning random splits repeatedly, Vim prefers existing views of matching buffers and keeps your window layout cleaner.
Tips
- Add this to your vimrc for persistent behavior.
- Pair with
:set hiddenso modified buffers can be left safely when switching contexts.