From 42c5eae49d7a02fa56cda9e6d22adf458d2618a3 Mon Sep 17 00:00:00 2001 From: Nick Nisi Date: Thu, 8 Nov 2012 08:44:19 -0600 Subject: [PATCH] Updating loading of local vimrc files This is based on the reddit topic http://www.reddit.com/r/vim/comments/12tpf9/per_project_vim_settings/ --- vim/vimrc.symlink | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/vim/vimrc.symlink b/vim/vimrc.symlink index 60b8e70..efe653d 100644 --- a/vim/vimrc.symlink +++ b/vim/vimrc.symlink @@ -260,6 +260,7 @@ endfunction nnoremap / :call ToggleNuMode() +" find out what syntax stack a statement belongs to nmap s :call SynStack() function SynStack() if !exists("*synstack") @@ -268,6 +269,25 @@ function SynStack() echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")') endfunction +function! ApplyLocalSettings(dirname) + " convert windows paths to unix style + let l:curDir = substitute(a:dirname, "\\", "/", "g") + + " walk to the top of the dir tree + let l:parentDir = strpart(l:curDir, 0, strridx(l:curDir, "/")) + if isdirectory(l:parentDir) + call ApplyLocalSettings(l:parentDir) + endif + + " now walk back down the path and source .vimsettings as you find them. + " child directories can inherit from their parents + let l:settingsFile = a:dirname . "/.vimrc.local" + if filereadable(l:settingsFile) + exec ":source" . l:settingsFile + endif +endfunction +autocmd! BufEnter * call ApplyLocalSettings(expand(":p:h")) + """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Plugins """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" @@ -295,19 +315,3 @@ let g:ctrlp_custom_ignore = { " search the nearest ancestor that contains .git, .hg, .svn let g:ctrlp_working_path_mode = 2 - -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" => Local vimrc -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" load a custom, per machine vimrc if available -if filereadable(glob("~/.vimrc.local")) - source ~/.vimrc.local -endif - -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" => Local, Per Project vimrc -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" - -if filereadable(".vimrc.project") - source .vimrc.project -endif