How do I reindent the whole file without adding extra jump-list entries?
Answer
:keepjumps normal! gg=G
Explanation
Bulk formatting commands are common in cleanup sessions, but they often leave side effects in your navigation history. Wrapping a full-buffer reindent in :keepjumps avoids polluting the jump list, so your usual <C-o>/<C-i> workflow remains meaningful after formatting. This is especially useful when you need to reindent quickly in the middle of investigation or review.
How it works
:keepjumpsexecutes the following command without recording jump-list entries caused by cursor movementnormal!runs raw Normal-mode keys (ignores custom mappings for safety and predictability)gg=Gjumps to first line and applies=indentation operator through end of file- Combined, you get whole-buffer indentation with minimal navigation side effects
Example
Before:
if ready:
print("start")
if debug:
log("x")
Run:
:keepjumps normal! gg=G
After (indentation normalized to filetype rules):
if ready:
print("start")
if debug:
log("x")
Tips
- Use
gg=Gonly when filetype indent settings are correct (:set filetype?) - If you want to preserve marks as well, combine with
:keepmarksin scripted workflows - For a smaller scope, replace
gg=Gwith a motion like=apor=}