Skip to content

Instantly share code, notes, and snippets.

@hanxi
Created January 25, 2019 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hanxi/58c6137b5871b2a4f1c0609ef6e523f7 to your computer and use it in GitHub Desktop.
Save hanxi/58c6137b5871b2a4f1c0609ef6e523f7 to your computer and use it in GitHub Desktop.
function! SearchRoot()
let l:scm_list = ['.root', '.svn', '.git']
for l:item in l:scm_list
let l:dirs = finddir(l:item, '.;', -1)
if !empty(l:dirs)
return fnamemodify(l:dirs[-1].'/../', ':p:h')
endif
endfor
return getcwd()
endfunction
let g:root_dir = SearchRoot()
autocmd BufEnter * exe ':cd '.g:root_dir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment