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 jumpscreen: keeps the cursor on the same screen line — content stays visually stabletopline: 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.luaasvim.opt.splitkeep = "screen"orinit.vimasset splitkeep=screen - Pair with
set splitbelow splitrightfor consistent split behavior - Use
toplineif you prefer the top of the window to stay anchored rather than the cursor line