Simplify directory setup

Mon, 12 Jun 2017 18:20:55 -0400

author
Meredith Howard <mhoward@roomag.org>
date
Mon, 12 Jun 2017 18:20:55 -0400
changeset 603
ae87c045d04b
parent 602
2f9ceb002f74
child 604
0d7437c668d0

Simplify directory setup

.vimrc file | annotate | diff | comparison | revisions
--- a/.vimrc
+++ b/.vimrc
@@ -4,6 +4,7 @@ set nocompatible
 
 " on windows and not cygwin
 let g:on_windows = (has('win32') || has('win64'))
+let g:myvim      = $HOME . (g:on_windows ? '/vimfiles' : '/.vim')
 let s:filename   = expand('<sfile>')
 
 " Set up Vundle and plugins  {{{
@@ -195,35 +196,19 @@ set sessionoptions=buffers,curdir,localo
 " Enable enhanced % matching in ruby
 runtime macros/matchit.vim
 
-if g:on_windows
-  let $MYVIM=$HOME.'/vimfiles'
-
-  if !filewritable( $MYVIM . '/var' )
-    silent execute '!mkdir "'.$HOME.'\vimfiles\var"'
-  endif
-  if !filewritable( $MYVIM. '/var/backup' )
-    silent execute '!mkdir "'.$HOME.'\vimfiles\var\backup"'
-  endif
-  if !filewritable( $MYVIM . '/var/tmp' )
-    silent execute '!mkdir "'.$HOME.'\vimfiles\var\tmp"'
-  endif
-  if !filewritable( $MYVIM . '/var/undo' )
-    silent execute '!mkdir "'.$HOME.'\vimfiles\var\undo"'
+for subdir in ['backup', 'tmp', 'undo']
+  if !filewritable(g:myvim . '/var/' . subdir)
+    call mkdir(g:myvim . '/var/' . subdir, 'p', 0700)
   endif
-
-else
-  let $MYVIM=$HOME.'/.vim'
+endfor
 
-  if !filewritable( $MYVIM . '/var/backup' )
-    silent execute '!mkdir -p "'.$MYVIM.'/var/backup"'
-  endif
-  if !filewritable( $MYVIM . '/var/tmp' )
-    silent execute '!mkdir "'.$MYVIM.'/var/tmp"'
-  endif
-  if !filewritable( $MYVIM . '/var/undo' )
-    silent execute '!mkdir "'.$MYVIM.'/var/undo"'
-  endif
+set backup
+let &backupdir = g:myvim . '/var/backup//,.'
+let &directory = g:myvim . '/var/tmp//,.'
 
+if has('persistent_undo')
+  set undofile
+  let &undodir = g:myvim . '/var/undo//,.'
 endif
 
 if g:on_windows
@@ -239,16 +224,6 @@ set guioptions-=T "no toolbar, menu, tea
 set guioptions-=m
 set guioptions-=t
 
-set backupdir=$MYVIM/var/backup//,.
-set directory=$MYVIM/var/tmp//,.
-
-set backup
-set autowriteall
-
-if has('persistent_undo')
-  set undofile
-  set undodir=$MYVIM/var/undo//,.
-endif
 " }}}
 
 
@@ -365,7 +340,7 @@ let g:tagbar_type_perl = {
         \ 'l:aliases',
         \ 'd:pod:1:0',
     \ ],
-    \ 'deffile' : '$MYVIM/ctags/perl.cnf'
+    \ 'deffile' : g:myvim . '/ctags/perl.cnf'
 \ }
 
 let g:tagbar_type_elixir = {

mercurial