Created
March 28, 2012 12:34
-
-
Save jnothman/2225818 to your computer and use it in GitHub Desktop.
source a git repository-specific .vimrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! SourceGitVimrc(dir) | |
let gitroot = system("cd " . fnameescape(a:dir) . "; git rev-parse --show-toplevel 2>/dev/null") | |
" Strip trailing newline and escape | |
let gitroot = substitute(gitroot, "\\n*$","","") | |
if strlen(gitroot) && filereadable(gitroot . '/.vimrc') | |
execute "source " . fnameescape(gitroot) . '/.vimrc' | |
endif | |
endfunction | |
autocmd BufRead * call SourceGitVimrc(expand("<afile>:p:h")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment