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

How do I open the alternate buffer in a new split while keeping my current window unchanged?

Answer

:leftabove sbuffer #

Explanation

If you often compare your current file against the previously visited buffer, replacing the current window is disruptive. :leftabove sbuffer # opens that alternate buffer in a new split above the current one, preserving your active editing context. It is a precise workflow for code review, side-by-side diff prep, or cross-referencing without retyping buffer names.

How it works

  • :leftabove is a split modifier that controls placement of the new window
  • sbuffer opens an existing buffer in a split instead of replacing the current window
  • # is the alternate-buffer marker (same target used by <C-^>)

Unlike opening by filename, this uses Vim's buffer state directly. That means no path completion and no disk reload when the alternate buffer is already loaded.

Example

You are editing service.go, and handler.go is your alternate buffer from the last jump.

Current window: service.go
Alternate (#): handler.go

Run:

:leftabove sbuffer #

Result:

Top split:    handler.go
Bottom split: service.go

Your current edits remain visible, and you can move between both files with normal window motions.

Tips

  • Use :rightbelow sbuffer # when you prefer the new split below
  • Combine with :set splitbelow splitright for predictable layout defaults
  • Use :ls if # is not the buffer you expected

Next

How do I swap the first two comma-separated fields on each line with one substitute command?