How do I indent the current line without changing local marks in Vim?
Answer
:lockmarks normal! >>
Explanation
When you run editing commands from the command line, Vim usually updates special marks like '[ and '] to the changed text. That is often helpful, but it can break a navigation flow if you rely on those marks right after a scripted edit. :lockmarks prevents mark updates while the wrapped command runs.
How it works
:lockmarkstells Vim to keep marks unchanged for the following Ex commandnormal! >>runs the built-in indent operator on the current line, ignoring mappings- The line is still modified, but change/yank marks are preserved from earlier work
:lockmarks normal! >>
Example
Before:
if ready {
log("done")
}
Cursor is on log("done"), and you run :lockmarks normal! >>:
if ready {
log("done")
}
The indentation changes, but your existing marks stay where they were, so jumps that depend on mark history remain stable.
Tips
Use this pattern for other scripted edits too, for example substitutions or macro execution from Ex mode when you want text changes without disturbing mark-based navigation.