How to white list a directory for ctrlp in vim

295 Views Asked by At

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

2

There are 2 best solutions below

0
Ignacio On BEST ANSWER

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)

0
romainl On

CtrlP searches/indexes your entire home directory because that's what you ask it to do.

You are probably starting Vim in your $HOME and doing :CtrlP from there. Since the working directory is $HOME you shouldn't be surprised that CtrlP scans all of it.

The solution to this non-issue is simply to use your shell and Vim as they are supposed to be used:

$ cd ~/code
$ vim