]> oss.titaniummirror.com Git - smckown/dotfiles.git/commitdiff
Swap/undo/backup is working again
authorR. Steve McKown <rsmckown@gmail.com>
Mon, 8 Jun 2015 19:42:10 +0000 (13:42 -0600)
committerR. Steve McKown <rsmckown@gmail.com>
Mon, 8 Jun 2015 20:00:57 +0000 (14:00 -0600)
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.

vimrc

diff --git a/vimrc b/vimrc
index 762ee3bee90c81f8a20e3bfa21db38e57f504d2d..cb58ffc8f85be56b864f312b5570dc28adaee85e 100644 (file)
--- 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