From: R. Steve McKown Date: Mon, 8 Jun 2015 19:42:10 +0000 (-0600) Subject: Swap/undo/backup is working again X-Git-Url: https://oss.titaniummirror.com/gitweb?p=smckown%2Fdotfiles.git;a=commitdiff_plain;h=ae7f2b211f3d9500f00aeb70abd1ad745c0d7ae8 Swap/undo/backup is working again Not sure, but sometime after the end of April the whole swap/undo/backup stuff quit working. It's almost as if a system configuration file changed, but I don't know what. In any case, the changes here to vimrc (~/.vimrc) gets things working even better: * If the directory structure used for these files, at ~/.local/share/vim, are not present, they are created. * If backups can be written, only the preferred location is made available. * If undo files can be written, only the preferred location is made available. --- diff --git a/vimrc b/vimrc index 762ee3b..cb58ffc 100644 --- a/vimrc +++ b/vimrc @@ -87,12 +87,34 @@ if has("autocmd") autocmd BufNewFile,BufRead *.plt,*.gnnuplot setf gnuplot endif -" Turn off backup and undo files if the proper dirs in ~/.local are not present. -let s:dir = has('win32') ? '~/Application Data/Vim' : has('mac') ? '~/Library/Vim' : '~/.local/share/vim' -if !isdirectory(expand(s:dir) . '/backup/') +" Setup swap/backup/undo +" Note that as of vim 7.4, backupdir // will not expand backup files to a full +" path as is the case with directory and undodir. +let s:dir = expand(has('win32') ? '~/Application Data/Vim' : has('mac') ? + \ '~/Library/Vim' : '~/.local/share/vim') +execute 'set directory^=' . s:dir . '/swap//' +if !isdirectory(s:dir . '/') + call mkdir(s:dir) +endif +if !isdirectory(s:dir . '/swap/') + call mkdir(s:dir . '/swap') +endif +if !isdirectory(s:dir . '/backup/') + call mkdir(s:dir . '/backup') +endif +if !isdirectory(s:dir . '/undo/') + call mkdir(s:dir . '/undo') +endif +if isdirectory(s:dir . '/backup/') + execute 'set backupdir=' . s:dir . '/backup//' + set backup +else set nobackup endif -if !isdirectory(expand(s:dir) . '/undo/') && exists('+undofile') +if has('persistent_undo') && isdirectory(s:dir . '/undo/') + execute 'set undodir=' . s:dir . '/undo//' + set undofile +else set noundofile endif