Not using versioning on your configuration files and editing them with Vim?
Use Vim’s backup option to automatically keep a copy of past versions. To put in your ~/.vimrc:
"Turn on backup option
set backup
"Where to store backups
set backupdir=~/.vim/backup//
"Make backup before overwriting the current buffer
set writebackup
"Overwrite the original backup file
set backupcopy=yes
"Meaningful backup name, ex: filename@2015-04-05.14:59
au BufWritePre * let &bex = '@' . strftime("%F.%H:%M")From now on, each time you’ll save a file (hit :w), Vim will save a copy in ~/.vim/backup/ with this syntax your-file.py@2016-10-25.14:58.
This honestly saves my life about once a year 😁.
@webcaptcha if you put these settings into your own
~/.vimrc, then, by default,rootwill not use those settings. Forrootto use similar settings by default, you would need to muck with a.vimrcfile in/rootor change system-wide defaults. These are not good options because they mean you are changing something thatrootinteracts with, and breakingrootis a really bad thing to risk.However,
sudohas a fix built right into it, just like they were thinking of you. :) Use the--preserve-envparameter (sudo --preserve-env vim) and your environment variables will be retained. For me, this is enough to retain myvimcustomizations, so I hope it works for you also.