Skip to content

Instantly share code, notes, and snippets.

@jnothman
Created March 28, 2012 12:34
Show Gist options
  • Save jnothman/2225818 to your computer and use it in GitHub Desktop.
Save jnothman/2225818 to your computer and use it in GitHub Desktop.
source a git repository-specific .vimrc
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