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

How do I keep scroll and cursor view when moving through jumplist history?

Answer

:set jumpoptions+=stack,view

Explanation

When you jump around large files with <C-o> and <C-i>, the default behavior can feel disorienting because your cursor position may return but your viewport context does not. Enabling jumpoptions with both stack and view makes jump navigation behave more like browser history while also restoring the prior window view. This is especially valuable in code review, debugging, and refactors where context loss slows you down.

How it works

  • :set jumpoptions+=stack,view appends two flags to the jumpoptions setting
  • stack changes jump list semantics to a stack-style flow, so forward history is dropped when you branch to a new location
  • view stores and restores window view details (such as scroll position) when revisiting jump points

Together, these options make repeated back/forward navigation much more predictable in long sessions.

Example

Before:

You jump from a function definition to multiple call sites and back.
Each return lands at roughly the right line but with a different screen context.

Apply:

:set jumpoptions+=stack,view

After:

Jumping back restores both the location and surrounding screen context,
so you keep your mental map while traversing code.

Tips

  • Use :set jumpoptions? to inspect your final effective value
  • Put this in your config only if stack-style jump behavior matches your workflow

Next

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