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

How do I make the Neovim jump list behave like a browser history stack instead of a ring?

Answer

:set jumpoptions=stack

Explanation

By default Vim's jump list is a ring: if you press <C-o> to go back several positions and then make a new jump, the list wraps around and future entries are preserved in a confusing cycle. Setting jumpoptions=stack changes the behavior to match a browser's back/forward history — when you jump back and then navigate to a new location, the forward history is discarded and the new position becomes the top of the stack.

How it works

  • With the default ring behavior, <C-o> (jump back) and <C-i> (jump forward) cycle through positions, but new jumps don't clear the forward history — they just advance the ring pointer.
  • With jumpoptions=stack, the jump list works like a LIFO stack: going back with <C-o> and then making any jump clears all the entries ahead of your current position and adds the new one as the top.
  • This prevents the confusing situation where pressing <C-i> after a new jump takes you to a completely unrelated location.
  • This option is Neovim-specific and was introduced to bring the jump list closer to how most users intuitively expect navigation history to work.

Example

Default ring behavior:

  1. Visit files: A → B → C → D
  2. Press <C-o> twice to go back to B
  3. Jump to file E
  4. Press <C-i> — you land in C (confusing — it came from the ring)

With jumpoptions=stack:

  1. Visit files: A → B → C → D
  2. Press <C-o> twice to go back to B
  3. Jump to file E
  4. Press <C-i> — nothing happens (forward history was cleared when you jumped to E)

Tips

  • View your current jump list with :jumps
  • Pair with <C-o> / <C-i> keybindings to navigate confidently
  • Use :set jumpoptions? to verify the current value

Next

How do I change the working directory to the folder containing the current file without affecting other windows?