Saturday, September 4, 2010

vim auto backup configuration

Long story short, if you use vim for your editing chores and if you want to enable a full fledged auto backup solution, copy paste the following into your .vimrc.

It creates backup files in ~/vimbackup/DATE/OrigFileName.HOUR.MIN.SEC each time you modify the file "OrigFileName".

" AUTOMATIC BACKUPS =====================================================
"enable backup
set backup
"
"Create a backup folder, I like to have it in $HOME/vimbackup/date/
let day = strftime("%Y.%m.%d")
let backupdir = $HOME."/vimbackup/".day
silent! let xyz = mkdir(backupdir, "p")
"
"Set the backup folder
let cmd = "set backupdir=".backupdir
execute cmd
"
"Create an extention for backup file, useful when you are modifying the
"same file multiple times in a day. I like to have an extention with
"time hour.min.sec
let time = strftime(".%H.%M.%S")
let cmd = "set backupext=". time
execute cmd
"
"test.cpp is going to be backed up as HOME/vimbackup/date/test.cpp.hour.min.sec
" ===================================================== AUTOMATIC BACKUPS

1 comment:

Larry said...

Love this feature, thank for the complete config guide !