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

How do I make buffer-jump commands reuse an existing tab before opening a new one?

Answer

:set switchbuf=usetab,newtab

Explanation

When you jump to buffers from quickfix, tags, or command-line completions, Vim's default window selection can feel unpredictable. The switchbuf option lets you control reuse behavior so navigation lands in already-open tabs before creating more layout churn. This keeps long-lived tab workflows much cleaner.

How it works

  • :set switchbuf=usetab,newtab configures how buffer-jump commands choose a destination
  • usetab prefers a tab that already displays the target buffer
  • newtab allows opening a new tab when no suitable existing location is found
  • This affects commands that honor switchbuf, including many buffer and quickfix navigation paths

Example

If api.go is open in another tab and you jump to it from quickfix:

:set switchbuf=usetab,newtab
:cnext

Vim will prefer the existing tab that already shows api.go instead of replacing your current split unexpectedly.

Before jump: tab1=current task, tab3=api.go already open
After jump:  focus moves to tab3 (reused), layout in tab1 stays intact

Tips

  • Add split or vsplit to switchbuf when you want jumps to stay in the current tab but open a new split.
  • Use :set switchbuf? to inspect the current behavior when navigation feels inconsistent.

Next

How do I jump to a literal search target without adding jump-list noise?