How can I keep the last code forever until next restart in vim

So my question is, I am writing some code in vim and then I want to go back 20 minutes early, then I type :earlier 20m

in vim. But it doesn't work if I quit vim once or even reboot with the system. I understand that it is stored in temporary registers, and as soon as vim reboots, it clears all register buffers. But is there a way to keep the last changes and apply some undo mechanisms. Actually I am working on some big project files and if something is wrong I cannot go back.

+3


source to share


1 answer


In Vim 7.3 or later, you can use an undo file.

Put this in your .vimrc.

set undofile

      

By default, this will save 100 undo actions. If you want more, you can install it manually by adding it to your .vimrc, with any amount you want:

set undolevels=100

      



Persistent undo will create undo files in the same directories as the files you are actually working on. If you want to put them in a separate directory so they don't clutter up your filesystem, add this to your .vimrc:

set undodir=~/.vim/undo

      

Then you need to create a directory. From the command line:

mkdir ~/.vim/undo

      

I would look at using version control instead of relying on vim persistent undo to keep track of changes in your projects.

+5


source







All Articles