Slow performance on CtrlP , it doesn't work to ignore some folders
Asked Answered
F

5

30

I tried to ignore the vendor by adding the following setting in .vimrc and I start my ctrlP by typing ff

map ff :CtrlP<.><cr>

However, it still tried to index all the files under the zeus folder including vendor folder.

enter image description here

But after finishing index, I still can NOT search the files under vendor,

enter image description here

Why does CtrlP take long time to index ?

129 "add ctrlp.vim setting
130 ""
131 set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*/vendor/*,*/\.git/*
132 let g:ctrlp_custom_ignore = 'tmp$\|\.git$\|\.hg$\|\.svn$\|.rvm$|.bundle$\|vendor'
133 let g:ctrlp_working_path_mode = 'ra'
134 let g:ctrlp_match_window_bottom=1
135 let g:ctrlp_max_height=25
136 let g:ctrlp_match_window_reversed=0
137 let g:ctrlp_mruf_max=500
138 let g:ctrlp_follow_symlinks=1
139 let g:ctrlp_clear_cache_on_exit=0

enter image description here

Here is my .vimrc, I thought there might be some settings conflicting each other

hi  Comment  ctermfg=6

"make vim save and load the folding of the document each time it loads"
""also places the cursor in the last place that it was left."
au BufWinLeave *.* mkview
au BufWinEnter *.* silent loadview


"function SetCafeOptions()
    "CoffeeCompile
    ":set nonu
    ":res -24
    ":res +24
"endfunction

set encoding=utf-8 
set fileencoding=utf-8 

colorscheme elflord            
set smartindent
set tabstop=4
set expandtab  
set shiftwidth=4

"make it autoreload
set autoread 

"auto move it last time the position you viewed
"make vim save and load the folding of the document each time it loads"
""also places the cursor in the last place that it was left."

"try to set show ansi color
if &term=="ansi" 
    set t_Co=0 
endif

"set expandtab

filetype on

if has("cscope")
    set csprg=/usr/bin/cscope
    set csto=0
    set cst
    set nocsverb
    " add any database in current directory
    if filereadable("cscope.out")
        cs add cscope.out
        " else add database pointed to by environment
    elseif $CSCOPE_DB != ""
        cs add $CSCOPE_DB
    endif
    set csverb
    set cscopetag
    set cscopequickfix=s-,g-,c-,d-,t-,e-,f-,i-
endif

"let Tlist can close windows at one time
let Tlist_Show_One_File=1
let Tlist_Exit_OnlyWindow=1
let Tlist_Ctags_Cmd = '/usr/local/bin/ctags'

" Key map
" Presee F4 and you can open the NERDTree
nnoremap <silent> <F4> :NERDTree<CR>  
"nnoremap <silent> <F3> :!/usr/bin/env python %<CR>
" Show function List with Tlist 
nnoremap <F12> :TlistToggle<CR>

" Map ctrl+q to ctrlw+ctrlw
"
"nnoremap <silent> <C-q>  :<C-w><C-w>

"switch in splitted window
map <c-d> <c-w>l
map <c-a> <c-w>h

"set highlight
set hlsearch

"set autocomplet 
"autocmd BufNewFile,BufRead *.html.erb set filetype=html.eruby
autocmd BufNewFile,BufRead *.html.erb set filetype=erb.html.eruby
filetype plugin indent on

"auto import python template
autocmd bufnewfile *.py 0r ~/common_lib/python_lib/tmpl.py


map ff :CtrlP<.><cr>
"set NerdTreeSize
let g:NERDTreeWinSize=12
let g:NERDTreeIgnore=['\.vim$', '\~$', '\vendor$']
"auto close the nerdtress window whe you open new file
"let g:ctrlp_dont_split = 'nerdtree'

set nocompatible " explictly get out of vi-compatible mode

set background=dark " we plan to use a dark background

syntax on " syntax highlighting on

set number " turn on line numbers

set ruler "always show current position along the bottom

set incsearch " do highlight as you type you search phrase

set ignorecase " case insensitive by default

set smartcase " if there are caps, go case-sensitive


"Rope vim
"let $PYTHONPATH .= ":~/install/ropehg/rope:~/install/ropehg/ropemode:~/install/ropehg/ropevim"
"source ~/install/ropehg/ropevim/ropevim.vim
"let g:pymode_rope_goto_def_newwin = "new"
"let ropevim_vim_completion=1
"Use Ctrl + ] . to autocomple
inoremap <C-]> <C-R>=RopeCodeAssistInsertMode()<CR>
map <leader>j :RopeGotoDefinition<CR>
map <leader>r :RopeRename<CR>

" Load the whole plugin
 let g:pymode = 1
" Load run code plugin
 let g:pymode_run = 1

"add ctrlp.vim setting
""
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*/vendor/*,*/\.git/*
let g:ctrlp_custom_ignore = 'tmp$\|\.git$\|\.hg$\|\.svn$\|.rvm$|.bundle$\|vendor'
let g:ctrlp_working_path_mode = 0
let g:ctrlp_match_window_bottom=1
let g:ctrlp_max_height=25
let g:ctrlp_match_window_reversed=0
let g:ctrlp_mruf_max=500
let g:ctrlp_follow_symlinks=1
let g:ctrlp_clear_cache_on_exit=0


"Vundle
 set rtp+=~/.vim/bundle/vundle/
 call vundle#rc()
 Bundle 'gmarik/vundle'
 Bundle 'tpope/vim-surround'
 Bundle 'Raimondi/delimitMate'
"coffee script"
 Bundle 'kchmck/vim-coffee-script'
 Bundle 'ack.vim'
 Bundle 'matchit.zip'
 Bundle 'kien/ctrlp.vim'
 "Markdown"
 "Bundle 'plasticboy/vim-markdown'
 ""Vim-scripts repo
 "Bundle 'The-NERD-Commenter'
 Bundle 'pep8'
 ""Bundle 'AutoClose'
 Bundle 'desert-warm-256'
 Bundle 'https://github.com/altercation/vim-colors-solarized.git'
 filetype plugin indent on

 nmap <leader>a <Esc>:Ack ""

 "folding code
 nnoremap <space> za
 vnoremap <space> zf

" pep8
let g:pep8_map='<leader>8'

"coffee script"
call pathogen#infect()



let Tlist_Use_Right_Window   = 1

"autocmd BufEnter * if &filetype == "" | setlocal ft=python | endif

"markdown https://github.com/plasticboy/vim-markdown/wiki"
"let g:vim_markdown_folding_disabled=1

"auto exec ruby and coffee script with F5 , remeber to save file before launching
autocmd FileType python map <leader>p :!python %<cr>
autocmd FileType ruby,rb map <leader>5 :w!<cr>:!ruby %<cr>
autocmd FileType * map <leader>e :qa!<cr>

"set extension .god as a Ruby file"
"au BufNewFile,BufRead *.god set filetype=ruby

"autocmd FileType coffee nmap <F5> :CoffeeCompile<cr>
"autocmd FileType coffee map <F5> :call SetCafeOptions()<cr>

"so ~/.vim/snippets/support_functions.vim

set re=1

autocmd Filetype gitcommit setlocal spell textwidth=72


 " enable per-project .vimrc files
   set exrc
 "   " Only execute safe per-project vimrc commands
     set secure"
Felicio answered 25/1, 2014 at 3:2 Comment(2)
You have a problem with CtrlP, why don't you use its isue tracker? That said, you should try */vendor/**/* in wildignore.Janus
Did you ever find an answer to this? Having the same issue.Rendering
D
89

Here are a few tips that should definitely speed up ctrlp :

let g:ctrlp_cache_dir = $HOME . '/.cache/ctrlp'
if executable('ag')
  let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
endif

In the above example, the first option tells ctrlp to persist the cache in the configured location, so when you launch vim again, it will read from there and load the cache (much faster).

The second option configures ctrlp to use ag (the_silver_searcher) instead of vim's native globpath() apis to search for files, this will drastically improve it's scanning speed, if you don't want to use ag, you can even use plain old grep and it still should be significantly faster. Check :h 'g:ctrlp_user_command' for more details.

Dismal answered 1/4, 2014 at 11:44 Comment(12)
Is -l necessary in the ag command (from quick experimentation/reading man ag I don't think so but I'd want to make sure)?Prolongate
Honestly I haven't experimented with that so much.Dismal
This answer is sickCachepot
Thanks so much! Got the indexing time on my app down from ~6 seconds to almost instant.Explicit
Huge improvements to my CtrlP! Also I'm wondering why you need the -g option? Isn't all files needed? Does the empty pattern do something? Thanks a lotCraddock
@Craddock without the -g option ag only lists files in the specified directly and not all files recursively from all nested directoriesDismal
@DhruvaSagar Thank you!Craddock
This is great and blazing fast to refresh! However, it causes me to loose the MRU search ability. Is there some way to keep that while still refreshing fast?Sinus
As per ctrlp documentation refresh should only delete removed file from MRU, shouldn't impact MRU searching otherwise.Dismal
Holy moly, what a game changer. Lightning fast.Spry
Almost 5 years later and this answer still saved my life, made ctrlp actually usable.Triggerhappy
Thanks for taking me to the world of Ag!Alimentation
I
8

As I explained here, if you type :help ctrlp-options and read a bit, you will find:

Note #1: by default, wildignore and g:ctrlp_custom_ignore only apply when globpath() is used to scan for files, thus these options do not apply when a command defined with g:ctrlp_user_command is being used.

Thus, you may need to unlet g:ctrlp_user_command (possibly set to a default command) to actually use wildignore. For instance, in your ~/.vimrc, add:

if exists("g:ctrl_user_command")
  unlet g:ctrlp_user_command
endif
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*/vendor/*,*/\.git/*
...

After that, you need to refresh your ctrlp cache: in Vim, press F5 in ctrlp mode, or run :CtrlPClearAllCaches, or remove the cache directory directly in your shell:

rm -r ~/.cache/ctrlp/      # On Linux

As for the indexing part (which seems to be your problem), it should follow your ignore rules. You can check the indexed files in ~/.cache/ctrlp/%path%to%your%project%folder.txt.

Immitigable answered 11/4, 2014 at 14:44 Comment(1)
Is there any other way to use ag as mentioned by @Dhruva, without using g:ctrlp_user_command?Commissionaire
S
8

Last resort for a quick startup

I tried everything I found in different places to improve the indexing speed of my ctrlp, but nothing helped. At the end, I settled with this:

let g:ctrlp_clear_cache_on_exit = 0

It keeps the ctrlp cache after you close VIM, so the next start up will be fast. And you can update the cache manually by pressing F5 anytime you need.

Shiest answered 8/7, 2016 at 6:19 Comment(2)
Why do you need to manually create the cache? Does the clear_cache_on_exit clear the cache, also mean that the cache is not automatically generated?Commissionaire
let g:ctrlp_clear_cache_on_exit = 0 I think this means the cache is generated only once. So if you add some files or rename some others, the cache won't get updated. You'll have to manually update them to see the new files, or new file names.Shiest
C
4

Found this bit while looking around the interwebs, and it has made indexing and searching for files instant.

let g:ctrlp_user_command = ['.git/', 'git ls-files --cached --others  --exclude-standard %s']

I'm not fully grasping what is happening here, so if anyone has a bit more knowledge to dissect this, I'd love to know what's happening behind the scenes.

Churr answered 27/4, 2016 at 17:10 Comment(2)
Well it's been a long time but for posterity, I believe what's happening here is that it's using git to directly list any folders that it detects are git repos. This is much faster than having to traverse the filesystem since git is already tracking every fileAzrael
This is the answer I was looking for. Thank you.Araceli
M
2

If you have ripgrep (rg) installed you can use it with CtrlP. It is much faster than the default file search. This is the incantation you need to make it work:

if executable('rg')
  let g:ctrlp_user_command = 'rg %s --files --color=never --glob ""'
  let g:ctrlp_use_caching = 0
endif

h/t Elliot Jackson

Myatt answered 13/2, 2020 at 19:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.