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
:changesto view the full changelist with line numbers and text previews
Example
Suppose you edited a file in this order:
- Changed a word on line 10
- Deleted a line on line 45
- 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
gito jump to the last insert location and enter insert mode in one step — it's likeg;plusicombined - 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