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

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

  • useopen reuses an existing window showing the target buffer when possible.
  • usetab allows jumping to a tab that already has that buffer open.
  • newtab creates 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 hidden so modified buffers can be left safely when switching contexts.

Next

How do I launch a GDB session in Vim with the built-in termdebug plugin?