HeadlinesBriefing favicon HeadlinesBriefing.com

Vi Undo Evolution: From Single-Level to Multi-Level Systems

Hacker News: Front Page •
×

The original Bill Joy vi editor implemented only a single level of undo, where the 'u' command toggled between undoing and redoing the last change. This behavior became standardized in POSIX and the Single Unix Specification, requiring 'u' to function identically to ex's undo command. The specification mandates that 'u' reverse changes made by the last command that modified the edit buffer, including undo operations.

Vim and its derivatives broke from POSIX compliance to implement multi-level undo and redo using 'u' for undo and Ctrl-r for redo. This approach allows users to undo multiple changes sequentially and intersperse undo operations with other commands like cursor movement and searching. Vim even supports counts for undo and redo operations, enabling bulk reversals. Nvi maintains POSIX compliance while supporting multi-level undo through the 'u.' pattern, where '.' extends the undo sequence.

Evil, the vi emulation for GNU Emacs, inherits Emacs' multi-level undo system but exhibits inconsistent behavior when mixing undo commands with other operations. The BusyBox vi implementation offers minimal functionality with optional multi-level undo support but lacks redo capabilities. The author argues that vim's approach represents the most human-friendly solution, providing predictable behavior that allows seamless integration of undo operations with regular editing workflows.