vim Backup

Wie mache ich autom. ein Backup der Datei die gerade bearbeitet wird?


set mouse=r
syntax on
colorscheme torte

" check with F8 the changes from the modified and original file
nmap <F8> :w !diff % - 2> /dev/null<CR>

" create variable for .vimconf
let vimconf = expand('%:p:h') . "/" . ".vimconf"

" if .vimconf file exists in the directroy load it
if filereadable(vimconf)
        exec "source".fnameescape(vimconf)

Jetzt muss nur noch das file .vimconf in das Verzeichnis kopiert werden, wo vim autom. Backup's erstellen soll


" create variable of the archive directory
let archivedir = expand('%:p:h') . "/" . "archive"

" disable restore screen after vim exit, it's required for diff output
set t_ti=""
set t_te=""

" check if archive directory is available, created if needed
if !isdirectory(archivedir)
    call mkdir(archivedir , "p")

" enable backup and set backup directory
set backup
set writebackup
let &backupdir=archivedir

" run autocommand and save "original" file before the modified file will be saved
autocmd BufWritePre * let &backupext = '_' . strftime("%Y%m%d_%H%M%S")
autocmd BufWritePre * :silent !cp -f % $(echo %:p:h)/archive/$(echo %:t)_old 2> /dev/null

" make a diff of the file new file and old file
autocmd VimLeave * :silent !echo -e "\n\n******************************\n*** diff new_file old_file ***\n******************************\n\n------ diff begin ------" ; diff % $(echo %:p:h)/archive/$(echo %:t)_old 2> /dev/null | less -FeX ; echo -e "------ diff end --------" ;rm -f $(echo %:p:h)/archive/$(echo %:t)_old 2> /dev/null
doku/vim_backup.txt · Zuletzt geändert: 2017/07/05 13:48 von smicha


Deine IP ist