3 ms·
Can I add something from .vimrc? If you put the commands: set undofile set undodir=~/.vim/undodir You get infinite undo in your files. Now when you go i
by AJRF 8y ago
Can I add something from .vimrc?
If you put the commands:
set undofile
set undodir=~/.vim/undodir
You get infinite undo in your files.
Now when you go into a file, delete or add some text and close your terminal down, the next time you enter vim you can (re|un)do previous operations.
Has saved my ass more times than I care to mention over my career!
- martin_ 8y agoThis is awesome! Be sure to mkdir ~/.vim/undodir first as vim won't do it for you (or didn't for me)
- m3at 8y agoLate on this but in case it's useful: if !isdirectory($HOME . "/.vim/undodir") call mkdir($HOME . "/.vim/undodir", "p") endif set undofile set undodir=~/.vim/undodir
- midgetjones 8y agoI can't believe I didn't know about this! Thanks so much :)
- AJRF 8y agoI don't want to sound hyperbolic but its kind of a game changer for text editing. I understand why developers don't have it on by default in other text editors (space) but seeing as I don't fill my HDD with movies or games or any other large media like that, i've got all the space in the world.
- midgetjones 8y agoI actually wrote 'game changer' in my original comment, and got rid of it for the same reason! Now that I've added it to my vimrc, I'm now upping it to 'life-changing'
- Tepix 8y agoWhich version of vim added support for this?
- AJRF 8y ago7.3 I think - https://lwn.net/Articles/401002/ https://lwn.net/Articles/401002/
- packetpirate 8y agoDamn! My work machine is cut off from outside networks and restricted to the versions of packages on their repo. Guess I can't use it. :/
- amadio 8y agoYou can try Gentoo prefix to install stuff into your $HOME: https://wiki.gentoo.org/wiki/Project:Prefix https://wiki.gentoo.org/wiki/Project:Prefix
- IanCal 8y agoExcellent if you also use gundo, which gives a nice visual interface to the undo tree in vim. https://sjl.bitbucket.io/gundo.vim/ https://sjl.bitbucket.io/gundo.vim/
- cyfex 8y agoYou can also delete old (older than 90 days) undo files with the following in your .vimrc: let s:undos = split(globpath(&undodir, '*'), "\n") call filter(s:undos, 'getftime(v:val) < localtime() - (60 * 60 * 24 * 90)') call map(s:undos, 'delete(v:val)')
- aprao 8y agoThis is amazing! Just a note: I had to mkdir the directory in ~/.vim to get it work.