How do I jump to the top of a file without creating a new jumplist entry?
Answer
:keepjumps normal! gg
Explanation
Sometimes you need to make a quick structural move (for example, jump to top, inspect context, then return) without polluting jump navigation history. Wrapping a movement in :keepjumps performs the action while preserving the current jumplist state. This is useful in refactor and review sessions where jump-history quality matters for fast backtracking.
How it works
:keepjumps normal! gg
:keepjumpstells Vim to avoid recording new jumplist entries for the wrapped commandnormal!runs raw Normal-mode keys, bypassing user mappingsggjumps to the first line of the buffer
Example
You are deep in a file, run a quick top-of-file check, then return with <C-o>.
Before: jumplist points to meaningful navigation steps in your current task
Run: :keepjumps normal! gg
After: cursor moves to line 1, but jumplist remains clean
Tips
- Use the same pattern with other large motions, for example
:keepjumps normal! G - This pairs well with scripted edits where you do not want helper jumps to affect user navigation
- Prefer
normal!overnormalto avoid surprises from custom mappings