undo(2)undo - Undo the last edit
n undo (C-x u)
undo removes the last n edits made to the current buffer. The undo(2m) buffer mode must be enabled for this command to operate.
When n is -1, undo discards all of the current undo history for the buffer without performing any undo operation. This can be used to free the memory consumed by the undo history after completing significant editing.
When n is less than -1 (e.g. -2), undo inserts an undo boundary. By default, all edits performed within a single macro execution are treated as one undo group and are removed by a single call to undo. Calling -2 undo from within a macro creates a break point so that edits made before the call form one undo group and edits made after form a new, separate undo group, each requiring their own call to undo to reverse. Multiple boundaries may be inserted by calling -2 undo more than once.
The undo information is retained up until the next save operation, at which point the undo information is discarded. When editing large files with gross changes then it is advisable to either disable undo mode, or save frequently to flush the undo buffer, thereby keeping MicroEmacs memory requirements reasonable (most UNIX users have restrictions on the amount of memory that may be consumed by a single process. Windows is restricted by the amount of virtual memory (or swap space)).
The following macro demonstrates the use of the undo boundary. After executing test-multi-step-undo, the first call to undo removes only CD; a second call removes AB.
define-macro test-multi-step-undo insert-string "A" insert-string "B" -2 undo insert-string "C" insert-string "D" !emacro
Ref: undo(2) File: m2cmd136.2 Date: 2026/06/19
(c) Copyright JASSPA 2026