vimctrlp

How to white list a directory for ctrlp in vim


Ctrlp currently searches/indexes my entire home directory, how can I tell it to only index ~/code?


Solution

  • You have several options to configure where CtrlP will search for files. You will have to add these to your .vimrc file.

    For example, in my case I use ag to perform the search:

    let g:ctrlp_user_command = 'ag %s -l --hidden --nocolor -g "" --ignore .git'
    

    Normally CtrlP will look into the directory of the current project. If you always want to search in ~/code like you ask, you could add this custom command (in OSX):

    let g:ctrlp_user_command = 'find ~/code -type f ! -path "*.git*"'
    

    You could even add extra directories, like:

    let g:ctrlp_user_command = 'find ~/code ~/foo ~/bar -type f ! -path "*.git*"'
    

    However, I advise to not fix the directory where CtrlP will look and leave it to search for the project of the current file (see let g:ctrlp_working_path_mode)