select-undo.nvim update: core rewritten, you can now undo any line without losing newer changes
A while back I shared select-undo.nvim, a plugin to undo specific lines instead of the whole-buffer chronological undo. The early version had known bugs (reverting a line could impact its neighbor).
Finally after a year I got some time to make some changes. This update is a full rewrite of the core and it now works somewhat reliably (you guys can be the judge, because I might have tested in some bias scenarios).
What it does: edit line 10, then line 50. Native 'u' forces you to revert line 50 first. With this plugin you select line 10, press gu, and only that change reverts. Line 50 keeps your newer edit.
Mappings (visual mode):
- gu - revert the newest change in the selected lines; press again to step further back
- gU - revert the last change of every selected line in one press
- gC - revert only the selected characters, keeping other edits on the same line
What changed under the hood:
- Old version compared fixed line ranges across undo states, which broke when lines were inserted or deleted. Now it diffs each undo state and reverts only the hunks touching your selection
- A revert never touches lines outside your selection
- Each revert is one regular edit, so native u / Ctrl-r work on it as expected
- No more undo-tree pollution, works with undofile across sessions
- All mappings configurable
Repo: select-undo.nvim
Feedback and issues welcome. If you tried the old version and it bit you, this one is worth another look.