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

How do I keep the top line stable while changing split layouts in Neovim?

Answer

:set splitkeep=topline

Explanation

When you open, close, or resize splits in long files, the visible window region can shift in ways that break your reading flow. splitkeep controls how Neovim preserves screen context during these layout changes. Setting it to topline prioritizes keeping the top visible line anchored, which is useful when you treat the viewport as a stable reading frame while navigating complex code.

How it works

  • :set splitkeep=topline changes the split-preservation strategy
  • With topline, Neovim tries to keep the current top screen line fixed when windows are rearranged
  • This differs from the default behavior where cursor-relative preservation may still cause noticeable viewport shifts

For workflows that involve frequent split churn (quickfix navigation, tests in one pane, source in another), this can make navigation feel less jittery and easier to track mentally.

Example

Before:

You are reading a dense section near the top of a window.
Opening a new split causes the visible block to jump enough that you lose orientation.

Apply:

:set splitkeep=topline

After:

When splits are created or resized, the top line remains more stable,
so your visible reading context changes less abruptly.

Tips

  • Use :set splitkeep? to confirm the active mode
  • Try screen if you prefer preserving broader screen context instead of the topline anchor

Next

How do I uppercase text inside an HTML tag without changing the tags?