Hacker News new | more | comments | ask | show | jobs | submit login

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!




You 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)')


I can't believe I didn't know about this! Thanks so much :)


I 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.


I 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'


This is awesome! Be sure to mkdir ~/.vim/undodir first as vim won't do it for you (or didn't for me)


Late 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


Excellent if you also use gundo, which gives a nice visual interface to the undo tree in vim.

https://sjl.bitbucket.io/gundo.vim/


This is amazing! Just a note: I had to mkdir the directory in ~/.vim to get it work.


Which version of vim added support for this?



Damn! 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. :/


You can try Gentoo prefix to install stuff into your $HOME: https://wiki.gentoo.org/wiki/Project:Prefix




Applications are open for YC Summer 2019

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: