This script will search for .project.vim, ../.project.vim, ../../.project.vim etc until it finds one. If it finds one, it will source it.
This hasn't been modified to work on Windows, but shouldn't be hard to modify. Also I'm sure there are optimizations that could be made here, but it hasn't slowed me down at all.
function! s:findFileBackward(path, filename)
let file = a:filename
let path = a:path
if !strlen(path)
let path = '.'
endif
while !filereadable(file)
if path ==# '/'
return ''
endif
let path = system('cd '.shellescape(path.'/..').' && echo -n $PWD')
let file = path.'/'.a:filename
endwhile
return file
endfunction
function! FindFileBackward(filename)
" Try to resolve the file from the current buffer first
let file = s:findFileBackward(expand('%:h'), a:filename)
if !strlen(file)
" Try to resolve the file from the cwd
return s:findFileBackward(getcwd(), a:filename)
endif
return file
endfunction
let g:project_local_vimrc = FindFileBackward('.project.vim')
if filereadable(g:project_local_vimrc)
execute 'source ' . g:project_local_vimrc
endif
Pierre Penninckx 11 years ago
You can do something similar, without the "going up in the directory" with this:
set exrc
set secure
It will search for a .vimrc file in the directory you opened vim.
Florian Beer 11 years ago
Nice, I like the idea.
Btw. this is snippet number 100 Yay!