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

How do I jump back to where I last made an edit?

Answer

g; / g,

Explanation

The g; and g, commands let you navigate Vim's changelist — a per-buffer history of every position where you made a change. Press g; to jump to the previous edit location and g, to jump forward again. Unlike the jumplist, the changelist tracks only positions where text was actually modified.

How it works

  • Every time you modify the buffer (insert, delete, change), Vim records the cursor position in the changelist
  • g; moves backward through the changelist (older changes)
  • g, moves forward through the changelist (newer changes)
  • Each buffer maintains its own independent changelist
  • Use :changes to view the full changelist with line numbers and text previews

Example

Suppose you edited a file in this order:

  1. Changed a word on line 10
  2. Deleted a line on line 45
  3. Added text on line 80

Your cursor is currently on line 80. Pressing g; jumps back to line 45, pressing g; again jumps to line 10. Then g, brings you forward to line 45 again.

Tips

  • g; is far more useful than '' (jump to last jump position) when you want to return to where you were editing, not just navigating
  • Use gi to jump to the last insert location and enter insert mode in one step — it's like g; plus i combined
  • The changelist holds up to 100 entries per buffer
  • Combine with a count: 3g; jumps back three changes at once
  • Unlike marks, the changelist is maintained automatically — you don't need to set anything
  • . (dot mark) always points to the position of the last change — '.jumps to its line, ``. `` jumps to the exact position

Next

How do I edit multiple lines at once using multiple cursors in Vim?