Skip to content

possible autochdir workaround #36

Closed
@Konfekt

Description

@Konfekt

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions