In my code on vim, I did a lot of changes and then did a ZZ
(save and exit). But then I realized I didn't need those changes. Is there a way I can get back to the state before doing those changes using from some buffer where that data still might be stored. I haven't made any changes after the save & exit.
Undoing the Previous Command If you make a mistake in vi or if you just change your mind after an operation is completed, you can undo your last command by pressing u immediately after the command. You do not need to press Esc after you type u . By pressing u a second time you undo the undo.
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.
To undo an action press Ctrl+Z. If you prefer your mouse, click Undo on the Quick Access Toolbar. You can press Undo (or CTRL+Z) repeatedly if you want to undo multiple steps.
There's persistent undo option in vim, :h persistent-undo
Note: It was introduced in VIM 7.3 version, so for earlier versions, it will not work.
It can be turned on by placing following text in your .vimrc
:
if has('persistent_undo') "check if your vim version supports it set undofile "turn on the feature set undodir=$HOME/.vim/undo "directory where the undo files will be stored endif
Note: Before enabling this option, whatever that was lost, remains lost.
After enabling the option, you will be able to do subsequent undo/redo on whatever was added/deleted after enabling the option.
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