Don't break undo with next cursor movement
Ctrl-g U
Example
Insert 0 / 5Insert 1 / 5Insert 2 / 5Insert 3 / 5Normal 4 / 5Normal 5 / 5abInsertion point on line 1, column 3abInsertion point on line 1, column 3abInsertion point on line 1, column 2aXbInsertion point on line 1, column 3aXbCursor on line 1, column 2Cursor on line 1, column 1Don't break undo with next cursor movement.
Illustrated undo history
- Current block
typed ab
Keep the next left/right movement in this undo block.
Illustrated undo history
- Current block
ab, left movement, then X stay together
Move the insertion point between a and b.
Illustrated undo history
- Current block
ab, left movement, then X stay together
Insert X within the same undo block.
Illustrated undo history
- Current block
ab, left movement, then X stay together
Finish insertion.
Illustrated undo history
- Current block
ab, left movement, then X stay together
Undo the prepared ab insertion and X together.
Illustrated undo history
- Result
Original empty line restored
Before & after
abInsertion point on line 1, column 3Illustrated undo history
- Current block
typed ab
Cursor on line 1, column 1Illustrated undo history
- Result
Original empty line restored
ILLUSTRATION. Insert mode follows typing ab into an empty line. The next left movement stays on this line, so it can retain the same undo block.
Details & Vim help
Don't break undo with next cursor movement. Use in Insert mode. Availability and exact behavior can depend on Vim build features, options, mappings and editor state; the linked help is authoritative.