我使用ag
with ,如此处ctrlp
建议:
if executable('ag')
set grepprg=ag\ --nogroup\ --nocolor
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
let g:ctrlp_use_caching = 0
else
let g:ctrlp_custom_ignore = '\.git$\|\.hg$\|\.svn$'
let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files . --cached --exclude-standard --others']
endif
如果我从一个项目文件夹中运行 vim,并且其中有一个文件夹,.git
这将非常有用。但是,每当我从一个不是 git 项目根目录的目录运行 Vim 时,我都会得到一个空文件列表(没有结果)。为了澄清,使用以下文件夹层次结构:
Proj1/ # ctrlp works; finds foo.js and bar.js (unless they are .gitignored)
.git/
bin/
foo.js
bar.js
Proj2/ # ctrlp doesn't work; has empty file list
bin/
foo.py
bar.py
当我从同一目录中的命令行运行它时,实际的ag
命令 ,工作正常(它会找到所有文件)。ag %s -l --nocolor -g ""
这是我的全部ctrlp
配置:
map <c-p> :CtrlP<cr>
map <c-t> :CtrlPTag<cr>
let g:ctrlp_dotfiles = 1
let g:ctrlp_show_hidden = 1
let g:ctrlp_cmd = 'CtrlPMixed' " search anything (in files, buffers and MRU files at the same time.)
let g:ctrlp_cmd = 'CtrlP'
let g:ctrlp_working_path_mode = 'ra' " search for nearest ancestor like .git, .hg, and the directory of the current file
let g:ctrlp_match_window = 'top,order:ttb'
let g:ctrlp_max_height = 12 " maxiumum height of match window
let g:ctrlp_switch_buffer = 'et' " jump to a file if it's open already
let g:ctrlp_use_caching = 1 " enable caching
let g:ctrlp_clear_cache_on_exit = 0 " speed up by not removing clearing cache evertime
let g:ctrlp_mruf_max = 250 " number of recently opened files
if exists('g:ctrlp_user_command')
unlet g:ctrlp_user_command
end
if exists('g:ctrlp_custom_ignore')
unlet g:ctrlp_custom_ignore
end
if executable('ag')
set grepprg=ag\ --nogroup\ --nocolor
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'"
let g:ctrlp_use_caching = 0
else
let g:ctrlp_custom_ignore = '\.git$\|\.hg$\|\.svn$'
let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files . --cached --exclude-standard --others']
endif
let g:ctrlp_prompt_mappings = {
\ 'AcceptSelection("e")': ['<c-t>'],
\ 'AcceptSelection("t")': ['<cr>', '<2-LeftMouse>'],
\ 'ToggleType(1)': ['<c-u>', '<c-up>'],
\ 'ToggleType(-1)': ['<c-y>', '<c-down>'],
\ 'PrtExit()': ['<c-l>', '<esc>', '<c-c>', '<c-g>'],
\ 'PrtSelectMove("j")': ['<c-n>', '<down>'],
\ 'PrtSelectMove("k")': ['<c-p>', '<up>'],
\ 'PrtHistory(-1)': ['<c-j>'],
\ 'PrtHistory(1)': ['<c-k>'],
\ }
let g:ctrlp_buftag_types = {
\ 'coffee' : '--language-force=coffee --coffee-types=cmfvf'
\ }
我怎样才能ctrlp/ag
在 git repo 之外正常工作?