Skip to content

Instantly share code, notes, and snippets.

@kien
Created February 4, 2012 12:12
Show Gist options
  • Select an option

  • Save kien/1737475 to your computer and use it in GitHub Desktop.

Select an option

Save kien/1737475 to your computer and use it in GitHub Desktop.
Set the working directory to the project's root
" Set the working directory to the project's root, or to the parent directory
" of the current file if a root can't be found.
func! s:etwd()
let cph = expand('%:p:h', 1)
if match(cph, '\v^<.+>://') >= 0 | retu | en
for mkr in ['.git/', '.hg/', '.vimprojects']
let wd = call('find'.(mkr =~ '/$' ? 'dir' : 'file'), [mkr, cph.';'])
if wd != '' | let &acd = 0 | brea | en
endfo
exe 'lc!' fnameescape(wd == '' ? cph : substitute(wd, mkr.'$', '.', ''))
endfunc
au BufEnter * cal s:etwd()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment