Starting with Vim 7.0 this brilliant editor introduced a more powerful set of commands for Undo and Redo, using an undo tree. Being lazy, I didn’t fully get to grips with this and as a result didn’t really understand what I was doing. At times I accidentally deleted text I’d just writtenjjjk and then couldn’t recover it.
I knew the previous version of my work had to be there but I didn’t know how to get it back. After a time I realised that when things seemed to go wrong the solution was to use ‘g-‘ and ‘g+’ to go hack and forth in the undo tree. But this was a bit hit & miss.
If you have had a similar experience here are a couple of useful site where things are explained clearly;
The second of these sites has links to a couple of plugins which make life easier. I’m not generally an enthusiast for plugins but I’ve installed Histwin, which seems pretty good; I’ll probably try Undotree as well.
Finally, thanks to a third page I now know why I occasionally deleted work I’d just done and couldn’t recover it. See:
This explains why it happens (pressing Ctrl-u in Insert mode) and provides a way to avoid it.