在CtrlP上性能下降,它无法忽略某些文件夹

new*_*ike 28 vim ctrlp

我试图忽略vendor通过添加以下设置,.vimrcctrlP通过键入启动我ff

map ff :CtrlP<.><cr>
Run Code Online (Sandbox Code Playgroud)

但是,它仍然试图索引zeus包含vendor文件夹的文件夹下的所有文件.

在此输入图像描述

但在完成索引后,我仍然可以NOT搜索下的文件vendor,

在此输入图像描述

为什么CtrlP需要很长时间才能编入索引?

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
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

这是我的.vimrc,我以为可能会有一些设置相互冲突

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"
Run Code Online (Sandbox Code Playgroud)

Dhr*_*gar 78

这里有一些提示应该加速ctrlp:

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

在上面的示例中,第一个选项告诉ctrlp将缓存保留在配置的位置,因此当您再次启动vim时,它将从那里读取并加载缓存(更快).

第二个选项配置ctrlp使用ag(the_silver_searcher)而不是vim的native globpath()apis来搜索文件,这将大大提高它的扫描速度,如果你不想使用ag,你甚至可以使用普通的旧的grep,它仍然应该是显着的快点.查看:h 'g:ctrlp_user_command'更多详细信息.

  • 这个答案很恶心 (8认同)
  • 非常感谢!我的应用程序的索引时间从大约6秒到几乎瞬间. (2认同)

Ben*_*enC 7

正如我在这里解释的那样,如果你输入:help ctrlp-options并阅读一下,你会发现:

注意#1:默认情况下,wildignoreg:ctrlp_custom_ignore仅在使用globpath()扫描文件时应用,因此当使用g:ctrlp_user_command定义的命令时,这些选项不适用.

因此,您可能需要unlet g:ctrlp_user_command(可能设置为默认命令)才能实际使用wildignore.例如,在你的~/.vimrc,添加:

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

在此之后,你需要刷新ctrlp缓存:在Vim中,按F5ctrlp模式,或运行:CtrlPClearAllCaches,或直接在你的shell删除缓存目录:

rm -r ~/.cache/ctrlp/      # On Linux
Run Code Online (Sandbox Code Playgroud)

至于索引部分(这似乎是你的问题),它应该遵循你的忽略规则.您可以检查索引文件~/.cache/ctrlp/%path%to%your%project%folder.txt.


Nic*_*ick 6

紧急启动的最后手段

我尝试了在不同地方找到的所有内容,以提高ctrlp的索引编制速度,但没有任何帮助。最后,我解决了这个问题:

let g:ctrlp_clear_cache_on_exit = 0
Run Code Online (Sandbox Code Playgroud)

关闭VIM之后它将保留ctrlp缓存,因此下次启动会很快。而且,您可以随时按F5键手动更新缓存。