Files
scripts/vim/plugin/local-vimrc.vim

55 lines
1.4 KiB
VimL

"
" Authors: Vahagn Khachatryan (vahagn DOT khachatryan AT gmail DOT com)
"
" Licence: http://www.opensource.org/licenses/mit-license.php
" The MIT License
"
" This file is based on Andy Dawson's independence.vim
"
"-----------------------------------------------------------------------------
"
" Section: Documentation
"
" The vim local-vimrc plugin loads a .vimrc file from upper directories if
" it exists. This allows you to override your vim settings on a directory tree
" basis.
" Section: Plugin header
"
" loaded_local_vimrc is set to 1 when initialization begins, and 2 when it
" completes.
if exists('g:loaded_locl_vimrc')
finish
endif
let g:loaded_local_vimrc=1
" Section: Event group setup
" Act when creating or loading a file
augroup LocalVimrc
au BufNewFile,BufRead * call s:LoadConfig()
augroup END
" Function: LoadConfig()
"
" If the file .vimrc exists in the root of a git project - load it
function s:LoadConfig()
let l:path = fnameescape(expand("%:p:h"))
if empty(l:path)
return
endif
let l:pathp = ""
while !filereadable(l:path.'/.vimrc') && l:pathp != l:path
let l:pathp = l:path
let l:path = fnamemodify(l:path, ":h")
endwhile
let l:vimrc = l:path . '/.vimrc'
if filereadable(l:vimrc) && l:vimrc != $MYVIMRC
exec ":source " . l:vimrc
endif
endfunction
" Section: Plugin completion
let g:loaded_local_vimrc=2