I often have a number of settings per project (and more generally per client) so it's useful for me to have a generalized way of specifying per-client settings. I create a file called local.vimrc
(or more generally, named <client-name>.vimrc
and symlinked) in the root of whatever project it is I'm working on and then let this do its magic...
function! LoadLocalVimrc(filename)
let l:filepath = fnamemodify(a:filename, ':h')
let l:file = findfile("local.vimrc", l:filepath . ";/")
if l:file != ''
let l:file = fnamemodify(l:file, ":p")
execute "source" l:file
execute "nnoremap <buffer> <F8> :$tabe " . s:this_file . "<CR>:sp " . l:file . "<CR>"
endif
endfunction
autocmd BufEnter * call LoadLocalVimrc(expand("<afile>"))
Then the local.vimrc
uses map <buffer> ...
and setlocal
to keep mappings and settings local to the buffers that use them (as I sometimes have files from different clients loaded up in different tabs).
(In that code snippet above I'm remapping F8 to open my vimrc and the local.vimrc in a new tab; s:this_file
is captured elsewhere as expand("<sfile>")
.)