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

How do I open the alternate (previously visited) buffer in a new split window?

Answer

<C-w>^

Explanation

Vim tracks the alternate buffer — the last file you were editing before the current one. You can toggle between the two with <C-6> (or <C-^>). But <C-w>^ does something more useful: it opens the alternate buffer in a new horizontal split without leaving the current window, letting you see both files at the same time.

How it works

  • The alternate buffer is marked with # in the :ls listing
  • <C-w>^ is equivalent to :split # — it splits and loads the alternate buffer
  • You can prefix a count to open a specific buffer number: {N}<C-w>^ opens buffer number N in a split

Example

You're editing main.go and previously had handler.go open:

:ls
  1 %a   "main.go"      line 42
  2 #    "handler.go"   line 10

Press <C-w>^ to get a horizontal split with handler.go on top and main.go below — both visible, both editable.

Or press 3<C-w>^ to split-open buffer number 3 regardless of what the alternate buffer is.

Tips

  • Use <C-w>v^ to open the alternate buffer in a vertical split instead (<C-w>v splits, then ^ loads the alt buffer — actually just use :vs # for vertical)
  • The alternate buffer resets when you open a new file, so this is most useful in active two-file workflows
  • Pair with <C-6> (no split) for quick toggling vs <C-w>^ (split) for side-by-side comparison

Next

How do I run text I've yanked or typed as a Vim macro without recording it first?