How do I jump back to locations where I previously made edits?
Answer
g; and g,
Explanation
Vim tracks every position where you made a change in the changelist. Using g; and g, you can jump backward and forward through these positions, making it easy to revisit code you recently edited — even across different parts of the file.
How it works
g;— jump to the position of the previous (older) changeg,— jump to the position of the next (newer) change:changes— display the full changelist with line numbers and text previews
The changelist is separate from the jump list (<C-o>/<C-i>). The jump list tracks movements, while the changelist tracks only positions where text was actually modified.
Example
You edit a function at line 50, then scroll to line 200 to edit another function, then go to line 10 to add an import. Now you want to get back to line 200:
g; " jumps to line 200 (previous edit)
g; " jumps to line 50 (edit before that)
g, " jumps forward to line 200 again
To see all tracked changes:
:changes
change line col text
3 50 4 func processData() {
2 200 12 return result
1 10 0 import "fmt"
>
Tips
- Use
3g;to jump 3 changes back in one motion - The changelist persists as long as the buffer is open
- With
:set undofile, the changelist is rebuilt from the undo history when reopening a file giis a related shortcut — it jumps to the last insert position and enters insert mode