Improved config setup via install.sh
This commit is contained in:
70
config/.vim/plugin/local-vimrc.vim
Normal file
70
config/.vim/plugin/local-vimrc.vim
Normal file
@@ -0,0 +1,70 @@
|
||||
"
|
||||
" 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_local_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:LocalVimrcLoadForFile()
|
||||
augroup END
|
||||
|
||||
" Function: LoadConfig()
|
||||
"
|
||||
" If the file .vimrc exists in the path - load it
|
||||
function s:LocalVimrcLoadForFile()
|
||||
let l:path = fnameescape(expand("%:p:h"))
|
||||
call g:LocalVimrcLoad( l:path )
|
||||
endfunction
|
||||
|
||||
" Function: LocalVimrcLoad()
|
||||
"
|
||||
" If the file .vimrc exists in the path - load it
|
||||
function! g:LocalVimrcLoad(path)
|
||||
let l:path = a:path
|
||||
if empty(l:path)
|
||||
return
|
||||
endif
|
||||
|
||||
let l:paths = []
|
||||
let l:pathp = ""
|
||||
while l:pathp != l:path
|
||||
let l:vimrc = l:path.'/.vimrc.local'
|
||||
if filereadable(l:vimrc) && l:vimrc != $MYVIMRC
|
||||
let l:paths = [ l:vimrc ] + l:paths
|
||||
endif
|
||||
"echo 'try'.l:path
|
||||
|
||||
let l:pathp = l:path
|
||||
let l:path = fnamemodify(l:path, ":h")
|
||||
endwhile
|
||||
|
||||
"echo l:paths
|
||||
for vimrc in l:paths
|
||||
exec ":source " . vimrc
|
||||
endfor
|
||||
|
||||
endfunction
|
||||
|
||||
" Section: Plugin completion
|
||||
let g:loaded_local_vimrc=2
|
||||
Reference in New Issue
Block a user