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

How do I jump back and forth between my two most recent cursor positions?

Answer

<C-o> / <C-i>

Explanation

Vim maintains a jumplist — a history of every "jump" you make (searches, marks, gg, G, %, etc.). Pressing <C-o> moves backward through this list, and <C-i> moves forward. This is your browser-style back/forward for code navigation.

How it works

  • <C-o> — jump to the older position in the jumplist (go back)
  • <C-i> — jump to the newer position (go forward)
  • Each jump stores the exact file, line, and column

What counts as a jump

Not every movement is a jump. These are jumps:

  • /search, ?search, *, #
  • gg, G, {N}G
  • {, }, (, ) (paragraph/sentence motions)
  • % (bracket matching)
  • Mark jumps: 'a, `a
  • H, M, L (screen positioning)
  • :tag, gd, gf, <C-]>

These are not jumps: j, k, w, b, e, f, t

View the jumplist

:jumps

Shows a numbered list of all positions with file and line info.

Example workflow

  1. You're editing main.go at line 50
  2. Press * to search for a word — jumps to line 120
  3. Press gd to go to its definition — jumps to line 10
  4. Press <C-o> — back to line 120
  5. Press <C-o> — back to line 50
  6. Press <C-i> — forward to line 120

Tips

  • The jumplist works across files<C-o> can take you to a completely different buffer
  • Vim stores up to 100 entries in the jumplist per window
  • The jumplist is per-window, not per-buffer
  • This is arguably the most important navigation feature after search — learn to use it reflexively

Next

How do I run the same command across all windows, buffers, or tabs?