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 [email protected]:58
.
This honestly saves my life about once a year 😁.
Updated answer:
@sql-sith I actually overcomplicated it 😂.
From
:help backupdir
so you can just add two slashes to the end of
backupdir
to get the desired result:and it will look like
Old answer:
Hi @sql-sith, the documentation can be found here: https://vimhelp.org/options.txt.html#%27bex%27. (Same as
:help bex
)https://vimhelp.org/builtin.txt.html#expand%28%29 (
:help expand
) has the information regarding the meaning of%
.Since this is the extension that is used, you can append to the filename. Something like this should help you:
The file would end up looking like this: