vimctrlp

Vim Ctrlp Plugin: ctrlp_root_markers ignores the values I set?


My root project directory has the following:

root/
    .git
    Assets
    Library
    obj
    Temp
    etc.

Ctrlp by default looks in this root directory. I want to set the directory it starts looking in to "Assets". I looked at the docs and read in a few links that I should use ctrlp_root_markers, so in my vimrc:

let g:ctrlp_root_markers = ['Assets']

But then calling Ctrlp in vim while I'm in any source file under Assets, it always starts its indexing/search from the root directory. It just ignores the values I set in the root markers list. (I also tried messing with ctrlp_working_path_mode)

I ended up using this function (which I found lurking SO):

function! FindProjectRoot(lookFor)
    let pathMaker='%:p'
    while(len(expand(pathMaker))>len(expand(pathMaker.':h')))
        let pathMaker=pathMaker.':h'
        let fileToCheck=expand(pathMaker).'/'.a:lookFor
        if filereadable(fileToCheck)||isdirectory(fileToCheck)
            return expand(pathMaker).'/'.a:lookFor
        endif
    endwhile
    return 0
endfunction

And then remapping C-p:

nnoremap <C-p> :CtrlP `=FindProjectRoot("Assets")`<CR>

Works fine. But if a feature should be included in the core plugin I feel it's redundant to have to work-around it.

Any ideas what I'm doing wrong in setting my root markers?

Appreciate any help!


Solution

  • What you are seeing is the expected behavior. According to the docs:

    'g:ctrlp_root_markers'
    Use this to set your own root markers in addition to the default ones (.git,
    .hg, .svn, .bzr, and _darcs). Your markers will take precedence:
    let g:ctrlp_root_markers = ['']
    

    Note that on a git project the .git folder is inside the project root, as shown by your example. By including Assets as a root marker you changed nothing.

    If you intend to change your project root to Assets then you should include a file/folder that lies inside that folder.