Custom ignore for ctrlp
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.
Also added. Thanks for the suggestion!
The new option is g:ctrlp_custom_ignore. Let me know how it works for you.
@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.
Was getting annoyed at this as well. Glad to know this is available! Testing now...
EDIT:

is isn't working for me :/
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"
else
call matchdelete(w:longlinehl)
unl w:longlinehl
echo "Long lines unhighlighted"
endif
endfunction
"" 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
@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.
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.
@fourcolors
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.
@fourcolors
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?
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))$'
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:
REPO
- 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
" http://robots.thoughtbot.com/faster-grepping-in-vim
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
endif
Any tips?
Hi folks, I'm using the .gitignore itself to filter the useless files in ctrlp, the way I described in superuser (https://superuser.com/questions/649714/can-i-get-the-vim-ctrlp-plugin-to-ignore-a-specific-folder-in-one-project/900794#900794):
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:
node_modules/
\.log$
...
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: http://stackoverflow.com/a/18601066
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!