It's not mentioned in the article but Vim (and NeoVim) keep undo/redo history in a tree rather than a simple linear timeline[1].
The practical usage is it's aways possible to get back to a previous state you were in, which is pretty neat.
e.g. You can undo 5 changes, try something else and decide that you prefered the text before you started undoing things. In most programs with a linear undo history you've wiped out your previous changes but not in Vim.
You can hop about the branches of the undo tree using the g+ and g- commands but it's much easier to add an undo tree visualiser plugin such as the venerable old Gundo[2].
(Incidentally, the documentation is wonderful: ‘The only downside to this more advanced yet simpler undo system is that it was inspired by Vim. But, after all, most successful religions steal the best ideas from their competitors!’)
Strange, I love GNU screen, and find the key combinations very easy and intuitive. However, I could never seem to master GNU's Emacs and what I find are very strange default key commands. I love vim for the reason of, what I personally find, very intuitive key combinations.
I just downloaded VSCode for the first time recently -- which I was delighted to find has a VIM mode. From what I read VSCode's VIM mode does not respect the undo tree of actual VIM.
fun fact: sublime text also has a vim mode (called "Vintage mode" which is just hilarious) that is built-in but disabled by default, rather than an extension like in vscode. vim keybinds are just the best.
I haven’t been using Emacs for a long time now, but isn’t the Emacs way better? With undo tree you don’t lose any history, but the same is true for what Emacs does by default and it is much easier to navigate the history, since every change is part of a linear history and undos and redos also get added to it.
I thought so too, it's a part I've always struggled with effectively using, cause I get lost so quickly so was happy for a moment. But then reading the comments first, I got disappointed before I even had a chance to open the article.
I find it impossible to use without a plugin. I use https://github.com/mbbill/undotree and map it to `U` since I realized I never use `U` and it's easy to remember. https://github.com/sjl/gundo.vim/ is also popular but I like that the former is in pure vimscript (and the interface is a lil' better IMO).
They are both useful. I'm a frequent committer but find myself using this, I wanna say, 0 - 3 times per month. It's one of those things that when you want it, you're really glad it exists.
Undo is something that's extremely useful after the fact - commits can accomplish the same end if you're fastidious about continuously committing but fall short if you only realize your need after you've made the edit.
Consider this capability being used over the span of seconds as just another text editing tool. It would be like saying we don’t need undo/redo at all, just use git.
Don't forget time-travel undo. If you get into a weird state with the undo tree, and g+/g- aren't helping, you can do ":earlier 5m" to go back to where you were 5 minutes ago, and ":later 30s" to step forward.
Unfortunately, when you're at "now" you can't do ":later 30m" to see the future.
> you can do ":earlier 5m" to go back to where you were 5 minutes ago
That's crazy! I've used vi/vim/neovim for so long, probably two decades, and I've never heard anything about this feature, yet so many cases this would have been helpful.
Must be hundreds of these features I still don't know about. What's the wildest less-known vim features people sit on and haven't shared with the rest of us yet? :)
I use this a lot when trying different ways of solving things or debugging.
Just today I was looking into a bug when I started worrying that it might be caused by a fairly recent improvement I made to the feature. I went to the file in question, went back two weeks with ":earlier 14d" then recompiled and confirmed the bug was already present without my change.
If you are using vim in the terminal pressing alt send an escape sequence when followed by another key press. So to go out of insert mode I usually press alt+ one of h/j/k/l
I was gonna make a quip that someone should really get on the ":later" feature, but then I realized that the modern LLM craze more or less is that feature.
I found that going into visual mode and going `gU` or `gU` + movement was just as useful to get uppercase and `U` itself could be safely remapped to mimick <C-r>
I had almost forgotten that single-level undo was ever a thing. I'm sure there are some applications still in production use that don't support multi-level undo/redo though.
Such as the base OpenBSD vi, which only supports a single-level undo, which I am using at this moment (and still learning how to use, after a few decades). vim got curb-canned a while ago due to various "that's nice, but how do I turn it off?" additions, in addition to having more code in header files than vi has in total. vi meanwhile is pretty bloated though has ex filters which are a huge step up from the standard editor. Multi-level undo? Don't really need it.
Its inscrutable undo and redo behaviour is probably the main reason why I never really tried to get further into Emacs. And that's when I had just access to original vi, not vim.
All I need is a classic bad VI. Only thing lacking is syntax colours and multiple undo.
I hate when people using ViM claim that they are vi users or experts...
I miss elVis also. ViM should be banned from all distros because it is literally nag-ware and charity ware (Uganda 's children thing). 30 years later we still can't edit files bigger than RAM size unless you want to use swap file ...
Even commodore 64 had editors which could edit files bigger than RAM and WITHOUT ANY kind of swapping to the disk.
I would guess that you just remember at which file offsets you need to insert what, and which offset ranges you need to delete from the original file — and on file save you just do a single linear sweep to update the file contents on disk.
The practical usage is it's aways possible to get back to a previous state you were in, which is pretty neat.
e.g. You can undo 5 changes, try something else and decide that you prefered the text before you started undoing things. In most programs with a linear undo history you've wiped out your previous changes but not in Vim.
You can hop about the branches of the undo tree using the g+ and g- commands but it's much easier to add an undo tree visualiser plugin such as the venerable old Gundo[2].
1. https://neovim.io/doc/user/undo.html
2. https://docs.stevelosh.com/gundo.vim/