Backups of edited files helped me to restore deleted lines of code more than once, but the default mechanism for creating backups in VIM is rather inconvenient - who needs
* ~ -files cluttering the working project directory?
I offer you a beautiful solution, which I hope will save you in a difficult moment, or at least save you precious time that VIM users like to appreciate;)
Since we decided not to store the backup files in the directory with the original files, we will invent a separate directory for these purposes. I found it convenient to store copies in
~ / .vim / backup / .
')
In order not to get confused in files with the same names from different directories, we will create in our copy of the tree subdirectories of the file system where the original file was located. For example, if the file being edited is located in the
/ etc / lighttpd / directory, the backup file will be placed in
~ / .vim / backup / etc / lighttpd / . In addition, in order to avoid unnecessary branching, for files from the home directory, we will forcibly collapse the local path into the usual one
~ .
Additionally, we will add the creation date to the backup file name, which will allow us to store daily (if necessary, monthly or hourly) copies of the files. For example:
~ / .vim / backup / etc / lighttpd / lighttpd.conf ~ 2009-08-11 ~ .
The implementation took 10 minutes of the lunch break, we add the following code to the local
~ / .vimrc :
" set backup " function! BackupDir() " let l:backupdir=$HOME.'/.vim/backup/'. \substitute(expand('%:p:h'), '^'.$HOME, '~', '') " , if !isdirectory(l:backupdir) call mkdir(l:backupdir, 'p', 0700) endif " let &backupdir=l:backupdir " let &backupext=strftime('~%Y-%m-%d~') endfunction " autocmd! bufwritepre * call BackupDir()
Unfortunately, I do not have the opportunity to check and fix the code for working in Windows.
Comments and criticism is welcome!
PS: I almost forgot,
my .vimrc is catching up :-)