In Vim, is there a way to select a block of text and use undo to only undo changes to that block of text?
Let's say I rewrite a function, then go and make some changes elsewhere in my file. Afterwards, I realize that my first function implementation was indeed better. I'd like to undo the changes I made in that function, but leave my subsequent additions intact.
I don't know if this is even possible, but I often find myself wanting this feature.
Remember, yo undo a change in Vim / Vi use the command u , and to redo a change which was undone use Ctrl-R .
2 Answers. Show activity on this post. You have only 1 level of undo if you are in Vi compatible mode. You are missing out on a number of features by being in 'compatible' mode.
Hit ctrl-z, and fire up vim with the new stuff you want. When you're done, quit the current vim session and come back to your old context with `fg`. The key observation is this stacks inductively, so you cant tumble down the dependency rabbit hole and always come back to the context you were at originally.
Linux (like other unices) doesn't natively provide an undo feature. The philosophy is that if it's gone, it's gone. If it was important, it should have been backed up. There is a fuse filesystem that automatically keeps copies of old versions: copyfs.
Currently... No. Vim 7.3 has undo branches that you can traverse but as far as I know Vim does not pay attention to any selected text during an undo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With