How do I reindent the whole buffer without adding jumplist entries?
Answer
:keepjumps normal! gg=G<CR>
Explanation
Whole-buffer reindent is common, but doing it naively can pollute your jumplist and break navigation flow during review. Prefixing the operation with :keepjumps lets you run a disruptive normal-mode command while keeping jump history clean. This is useful in large refactors where you want formatting fixes without losing your navigation context.
How it works
:keepjumpsexecutes the following command without recording jump-list entriesnormal!runs raw normal-mode keys, ignoring user mappingsggjumps to the first line=Greindents from the cursor to the end of file
Together, this produces a full-buffer reindent with predictable behavior and no extra jump noise.
Example
Given inconsistent indentation:
if (ready) {
console.log('start')
doWork()
}
Run:
:keepjumps normal! gg=G
Result:
if (ready) {
console.log('start')
doWork()
}
Your previous jump locations remain useful, so <C-o> and <C-i> still navigate your editing history instead of formatter-induced jumps.
Tips
- Use this pattern for other whole-buffer normal commands when jump history matters.
- Keep
normal!(with bang) to avoid accidental mapping side effects in customized setups.