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

How do I make Neovim restore the scroll position when navigating back through the jump list?

Answer

:set jumpoptions+=view

Explanation

By default, when you navigate the jump list with <C-o> (older) or <C-i> (newer), Neovim restores the cursor's line and column but does NOT restore where the window was scrolled. Adding view to jumpoptions makes Neovim also restore the exact scroll state, so the file looks exactly as it did when you were last there — like a browser's back button.

How it works

  • jumpoptions is a comma-separated list of flags that modify jump list behavior
  • The view flag (Neovim 0.10+) saves the window view (including scroll offset) for each jump entry
  • Add it non-destructively with +=: :set jumpoptions+=view
  • Works with <C-o>, <C-i>, and mark jumps like '' or `

Example

Without view: You're deep in a function at line 150 of a 500-line file. You jump to a reference at line 400. When you press <C-o> to go back, Vim puts the cursor at line 150 but the window may now show different content (e.g., centered on line 150, which may look different).

With view: <C-o> returns you to line 150 with the view scrolled exactly as you left it — same lines visible above and below the cursor.

Tips

  • Combine with stack for browser-like forward/back behavior: :set jumpoptions=view,stack
  • In Lua: vim.opt.jumpoptions:append('view')
  • Check current value with: :set jumpoptions?
  • Does not apply to marks that were set in a different scroll state — it restores the view that existed when the jump was made

Next

How do I prevent a window from switching to a different buffer in Neovim?