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

How do I prevent the cursor from jumping when opening a split in Neovim?

Answer

:set splitkeep=screen

Explanation

Controls how Neovim preserves the visual position of content when creating, closing, or resizing horizontal splits. With splitkeep=screen, the text visible at the cursor position stays on the same screen line, preventing disorienting jumps.

How it works

splitkeep accepts three values:

  • cursor (default): Neovim adjusts scrolling to keep the cursor centered in the new window, which can cause content to jump
  • screen: keeps the cursor on the same screen line — content stays visually stable
  • topline: keeps the topmost visible line the same after splitting

Setting screen or topline is especially noticeable when working deep in a file: instead of scrolling to re-center the cursor, the window content stays exactly where it was.

Example

With the default cursor setting, pressing :sp while looking at line 300 of a file may cause the window to scroll so line 300 is centered in each new pane.

:set splitkeep=screen

After this change, :sp leaves the visible content at the same screen position — no unexpected scrolling.

Tips

  • Available in Neovim 0.9+ only
  • Add to init.lua as vim.opt.splitkeep = "screen" or init.vim as set splitkeep=screen
  • Pair with set splitbelow splitright for consistent split behavior
  • Use topline if you prefer the top of the window to stay anchored rather than the cursor line

Next

How do I configure Vim's completion menu to show a popup without auto-selecting the first candidate?