tôi sử dụng ag
với ctrlp
, theo đề nghị here:Làm cách nào để định cấu hình ctrlp hoạt động chính xác với ag bên ngoài repo git?
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
này hoạt động tuyệt vời nếu tôi đang chạy vim từ một thư mục dự án với một thư mục .git
bên trong nó. Tuy nhiên, tôi nhận được một danh sách tập tin trống (không có kết quả) bất cứ khi nào tôi chạy Vim từ một thư mục không phải là gốc của một dự án git. Để làm rõ, với hệ thống phân cấp thư mục sau:
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
Các thực tế ag
lệnh, ag %s -l --nocolor -g ""
, hoạt động tốt khi tôi chạy nó từ dòng lệnh trong cùng thư mục (mà nó tìm thấy tất cả các file).
Dưới đây là toàn bộ ctrlp
cấu hình của tôi:
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'
\ }
Làm thế nào tôi có thể nhận được ctrlp/ag
để làm việc một cách chính xác bên ngoài của một repo git?
Bạn đã cung cấp liên kết phù hợp chưa, trong dòng đầu tiên của câu hỏi? Tôi không thấy bất cứ điều gì liên quan đến nó – yolenoyer
Xin lỗi về điều đó - liên kết được cập nhật. Đây là [một vimrc tương tự] (https://github.com/skwp/dotfiles/blob/master/vim/settings/ctrlp.vim) với một lệnh 'ag' hơi khác, có cùng hành vi với tôi (ví dụ: không hoạt động). – Sasgorilla
Bạn có nhận được '1' với': echo executable ('ag') '? – Tacahiroy