Custom ignore for ctrlp #58

jgallen23 opened this Issue Dec 16, 2011 · 28 comments


None yet

It would be nice to be able to set what files/directories to ignore without changing the wildignore setting. I use both ctrlp and Nerd Tree, but I want them to ignore different things. I don't want ctrlp to look inside the node_modules directory, but I want Nerd Tree to show the contents of that folder.

@kien kien added a commit that closed this issue Dec 18, 2011
@kien Custom ignore and default command options
* Extend jump-to-open-buffer to use <c-t> when jump_to_buffer = 2.
  Only works for buffers opened in another tab.  Suggested by @hail2u.
* Add g:ctrlp_default_cmd, option to reuse the default mapping for a
  different command.  Close #57.
* Add g:ctrlp_custom_ignore.  Close #58.
@kien kien closed this in 64dca5e Dec 18, 2011
kien commented Dec 18, 2011

Also added. Thanks for the suggestion!

The new option is g:ctrlp_custom_ignore. Let me know how it works for you.

blaenk commented Dec 19, 2011

@kien: just wanted to say this is a welcome coincidence this was just added considering I just found out about the great ctrlp and wanted something like this option. Thanks :) It does work fine.

@jgallen23: I have it working fine:

let g:ctrlp_custom_ignore = 'node_modules\|DS_Store\|git'

Notice the escaped regex OR operator. That caught me off guard for a while :)


Thanks @kien for the quick turnaround. You've done an amazing job on this plugin


I just want to say thanks for this addition to the plugin. It has made a world of difference navigating the Twitter codebase. Keep up the good work.

chevex commented Jan 13, 2014

Was getting annoyed at this as well. Glad to know this is available! Testing now...



is isn't working for me :/

chevex commented Feb 2, 2014

I placed this in my .vimrc file:

let g:ctrlp_custom_ignore = 'node_modules\|DS_Store\|git'

It worked wonderfully for me. The pipe (|) is the pattern delimiter. @fourcolors Post what you put in your .vimrc. Or better yet paste your whole .vimrc for even better context.


Thanks for the reply! This is what my .vimrc file looks like. I'm using YouCompleteMe as well. I'm not sure if this effects anything.

"" ----------------------------------------------------------------------------
""  Random other items
"" ----------------------------------------------------------------------------
" Custom ignore for ctrl-p
let g:ctrlp_custom_ignore = '\v[\/]\.(DS_Storegit|hg|svn|optimized|compiled|node_modules)$'
"let g:ctrlp_custom_ignore = 'node_modules\|DS_Store\|git'

" Ignore html in syntastic since it doesn't handle handlebars
let syntastic_mode_map = { 'passive_filetypes': ['html'] }

" Don't require saving a buffer before switching buffers
set hidden

" Set notes directory for vim notes
let g:notes_directories = ['~/Dropbox/Notes']

"" ----------------------------------------------------------------------------
""  Key bindings / Mappings
"" ----------------------------------------------------------------------------
" mapleader
let mapleader = ","

map <Leader>s :source $MYVIMRC<CR>
map <Leader>e :e $MYVIMRC<CR>
imap <Leader>a <C-n>
map <Leader>b :CtrlPBuffer<CR>

"" toggle and start nerdtree
map <Leader>ns :NERDTreeToggle<CR>

"" Add control tab support
noremap <c-tab> :tabnext<cr>

"" Fix command typos (stolen from Adam Katz)
nmap ; :

"" Highlight lines over 80 characters long by pressing leader H
nnoremap <Leader>H :call<SID>LongLineHLToggle()<cr>
hi OverLength ctermbg=none cterm=none
match OverLength /\%>80v/
fun! s:LongLineHLToggle()
  if !exists('w:longlinehl')
    let w:longlinehl = matchadd('ErrorMsg', '.\%>80v', 0)
    echo "Long lines highlighted"
    call matchdelete(w:longlinehl)
    unl w:longlinehl
    echo "Long lines unhighlighted"
"" End of highlighting lines

"" Treat <li> and <p> tags like the block tags they are
let g:html_indent_tags = 'li\|p'

"" ---------------------------------------------------------------------------
"" Text type
"" ---------------------------------------------------------------------------
"" For .rabl type
au BufRead,BufNewFile *.rabl setf ruby

"" For Stylus"
au BufRead,BufNewFile *.styl setf sass

"" For Haml
au! BufRead,BufNewFile *.haml setfiletype haml

"" Highlighting for .ejs files
au BufNewFile,BufRead *.ejs set filetype=html

"" Highlighting for .handlebars files
au BufRead,BufNewFile *.handlebars,*.hbs set ft=html syntax=handlebars

"" ---------------------------------------------------------------------------
"" Color Schemes
"" ---------------------------------------------------------------------------
"" Color scheme
syntax enable
"" set background=dark

"" Font stuff
set guifont=Inconsolata-dz\ for\ Powerline:h17

"" Colors in your font
set t_Co=256

set relativenumber
set number
set numberwidth=5
set nowrap
kien commented Feb 3, 2014

@fourcolors I'll need some details. What mode are you trying to use the custom ignore for (I suppose Files) and what exactly are you trying to ignore? Have you cleared the cache or restarted Vim? Delete the cache directory if you aren't sure.


I'm trying to ignore the node_modules folder in my project. I tried both cleaning my cache and restarting Vim with it not working.

kien commented Feb 5, 2014

Did you press <F5> in CtrlP or run :CtrlPClearAllCaches to clear the cache? If you want to be sure, delete the .cache/ctrlp dir in your home dir.



let g:ctrlp_custom_ignore = '\v[\/]\.(DS_Storegit|hg|svn|optimized|compiled|node_modules)$'

note the \. at the beginning. This is matching .hg, .svn, or.. .node_modules which is not what you want.

spig commented Mar 27, 2014


I also noticed the my mru cache wasn't clearing so I had to do it manually by removing the cache.txt from ~/.cache/ctlrp/mru - this was where I was still seeing files that I thought should be ignored.


This successfully ignores ./node_modules:

let g:ctrlp_custom_ignore = 'node_modules\|DS_Store\|git'

What about ignoring nodule_modules in subdirectories? Like ./examples/foo/node_modules?

spig commented May 10, 2014

Here is what I have that ignores all node_modules folders at any level I've tested:

let g:ctrlp_custom_ignore = '\v[\/](node_modules|target|dist)|(\.(swp|ico|git|svn))$'

lmartins commented Apr 2, 2015

Im still can't find a way to have ctrlp to ignore things like node_modules or jspm_packages in subfolders inside my git repo.

My repo has the following structure:

   - Project A
        - node_modules
   - Project B
        - node_modules
   - ...

No matter what I try, and I've tried every sample above, I always get results from those folders.
Btw, im using Ag silver, not sure if it has any relation with this.

" The Silver Searcher
if executable('ag')
  " Use ag over grep
  set grepprg=ag\ --nogroup\ --nocolor

  " Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
  let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'

  " ag is fast enough that CtrlP doesn't need to cache
  let g:ctrlp_use_caching = 0

Any tips?


Hi folks, I'm using the .gitignore itself to filter the useless files in ctrlp, the way I described in superuser (

To solve this with a file like .gitignore (based in the Nathan grep solution), I created a file named .ctrlpignore and put the patterns that should be ignored, separated by lines:


And my ctrlp configuration:

let g:ctrlp_user_command = 'find %s -type f | grep -v "`cat .ctrlpignore`"'

Maybe the .gitignore itself can be used to ignore the files in ctrlp, not needing to create a new file to do almost the same thing.

I hope it can help.


@lmartins From what I have read, custom_ignore is not working when using a custom finder.
You must create a .agignore in your home directory or in the project directory using the same syntax as a .gitignore.

Please refer to the following link for a deeper explanation:

lmartins commented May 9, 2015

Thanks @cabouffard , I did managed to get it working as I wanted, not really sure how. Im just switched to Vim recently, still a lot to learn ;)


Thanks @spig, this

let g:ctrlp_custom_ignore = '\v[\/](node_modules|target|dist)|(\.(swp|ico|git|svn))$'

is working properly.

Amazing project!


my workaround

let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files --exclude-standard -co |& egrep -v "\.(png|jpg|jpeg|gif)$|node_modules"']
hew commented Oct 27, 2015

I tried a bunch of these options. For me, the only one that seemed to work is

let g:ctrlp_custom_ignore = '\v[\/](node_modules|target|dist)|(\.(swp|ico|git|svn))$'

from @spig


Solution posted by @blaenk works wonderfully 👍

dzlab commented May 3, 2016

this is awesome, I got huge perf boost by ignoring target folder in a scala project.


let g:ctrlp_custom_ignore = '\v/|(.(swp|ico|git|svn))$'
works perfectly

ain commented Jul 28, 2016

@hew's version worked best for me as well. Thanks a lot for sharing!


Here's my g:ctrlp_user_command, which uses the silver searcher because it's so damn fast:

if executable('ag')
  let g:ctrlp_user_command = 'ag %s -l --nocolor --hidden -g ""'

and then my ~/.agignore:


It's working nicely for me.

atc- commented Dec 5, 2016

I was using ctrlp_user_command which prevented ctrlp_custom_ignore from working. Removing the former fixed the latter for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment