Created
February 4, 2012 12:12
-
-
Save kien/1737475 to your computer and use it in GitHub Desktop.
Set the working directory to the project's root
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
| " 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