If search in a long path directory like a/long/long/long/path/to/project/
with ag, the results list will contain the long path. Is there a way to get ride of project path in result list?
Example results list of 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() {
what expected:
test.txt: test.....
js/test2.js: test: function() {
Why I search with specfied directory path instead of cd
and search? I do the project wide search in vim with ag this way: find the project path and pass it to vim command which will use ag
to search with given path.
Solution
Ps: I use 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()