【发布时间】:2016-10-21 08:59:34
【问题描述】:
如果用 ag 在像a/long/long/long/path/to/project/ 这样的长路径目录中搜索,结果列表将包含长路径。有没有办法在结果列表中获取项目路径?
ag test a/long/long/long/path/to/project/ 的示例结果列表:
a/long/long/long/path/to/project/test.txt: test.....
a/long/long/long/path/to/project/js/test2.js: test: function() {
预期结果:
test.txt: test.....
js/test2.js: test: function() {
为什么我用指定的目录路径而不是cd 搜索并搜索?我使用 ag 在 vim 中进行项目范围搜索:找到项目路径并将其传递给 vim 命令,该命令将使用 ag 搜索给定路径。
解决方案
Ps:我用Plug 'mhinz/vim-grepper
function! VimGrepperConfig()
function! s:ag_at_project_root(keyword)
let root = s:find_root()
if !empty(root)
execute 'cd' root
execute 'GrepperAg' a:keyword
execute 'cd -'
else
execute 'GrepperAg' a:keyword
endif
endfunction
command! -nargs=1 AgAtProjectRoot call s:ag_at_project_root('<args>')
" ag search
no <Leader>/ :AgAtProjectRoot
endfunction
call VimGrepperConfig()
【问题讨论】: