5 ms·
I use this, in my .vimrc: :set backup :set backupdir=/home/kaz/.vimbackup :let &g:backupext=("." . strftime("%y-%m-%d.%H:%M:%S")) That's it. No messing
by kazinator 5y ago
I use this, in my .vimrc:
:set backup
:set backupdir=/home/kaz/.vimbackup
:let &g:backupext=("." . strftime("%y-%m-%d.%H:%M:%S"))
That's it. No messing around with git; protects files that are not in git, and can save you even in he face of "rm -rf .* *".
- kristjansson 5y agoIt's impossible not to note that emacs does this well too. Setting (setq backup-directory-alist `(("." "/home/user/some/dir/you/chose/backup/)) version-control t kept-new-versions 50 kept-old-versions 50) sets up a directory with many versions of every file ever edited. Additionally (setq auto-save-file-name-transforms `((".*" "/home/user/some/dir/you/chose/auto-save/" t))) does the same for even unsaved changes.
- kazinator 5y agoVim doesn't do it "well" with the settings above, just "good enough". The time stamp suffix is calculated just once when you start Vim, set in the global backupext option. If we :e edit files in an existing Vim session, they all get backups with that time stamp. It needs to be calculated as a buffer-specific value of that option, if there is such a thing, on every new edit.
- kazinator 5y agoI just found that the Vim manual recommends, right in the doc for backupext, the use of the BufWritePre hook instead, so: :au BufWritePre * let &backupext=("." . strftime("%y-%m-%d.%H:%M:%S")) This has the right effect that every time you save with :w, a new backup is made of the previous contents.
- clktmr 5y agoThere is also the `undofile` option, which stores your undo-history permanently on disk. You can also go to an earlier version of the file from 4 hours ago with `:earlier 4h`.