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

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
  • :keepjumps tells Vim to avoid recording new jumplist entries for the wrapped command
  • normal! runs raw Normal-mode keys, bypassing user mappings
  • gg jumps 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! over normal to avoid surprises from custom mappings

Next

How do I open the current Ex command in the command-line window for full-screen editing?