Closed
Description
Hello,
Just found the following lines in the documentation to CtrlP.vim, and they seem to behave well with respect to ctrlspace, better than set autochdir
or the workaround proposed here. The autocmd sets the cwd
to the current project root, similar to what ctrlspace does when opening it first time.
" A standalone function to 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:
function! s:setcwd()
let cph = expand('%:p:h', 1)
if cph =~ '^.\+://' | retu | en
for mkr in ['.git/', '.hg/', '.svn/', '.bzr/', '_darcs/', '.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.'$', '.', ''))
endfunction
autocmd BufEnter * call s:setcwd()
Metadata
Metadata
Assignees
Labels
No labels