How do I keep folds and viewport context when navigating jumps in Neovim?
Answer
:set jumpoptions=stack,view
Explanation
By default, jump navigation can feel lossy in long files: you jump back, but folds, topline, and viewport context do not always match what you were looking at before. Setting jumpoptions=stack,view improves this. stack makes the jumplist behave like browser history when you branch, and view restores more window state at jump destinations.
This is particularly useful when bouncing between references and definitions in large codebases with folds enabled. Instead of reorienting after every <C-o> or <C-i>, you get more predictable navigation and less cognitive overhead.
How it works
:set jumpoptions=...configures jump list behaviorstackdrops forward history when you branch from older jumps (history-stack semantics)viewrestores additional window view information when returning to jump targets
Example
You jump A -> B -> C, then go back to A and jump to D.
With stack, the old forward branch (B -> C) is discarded, so <C-i> does not unexpectedly revisit stale locations. With view, when you return to a jump, your screen context is closer to what it was when the jump was created.
Tips
- Put this in your config so behavior is consistent across sessions
- Pair with disciplined mark usage for even more reliable navigation
- If you prefer default ring-like behavior, keep
jumpoptionsunchanged