vimgrep as per vim's path variable

400 Views Asked by At

I usually work in multi location projects, where source files are distributed among different servers, databases, etc. What I isually do is to add these locations to vim's path, so, for instance, I can 'gf' into these files.

When firing a search to find a string using ":vimgrep", is it possible to somehow specify that the search is to be performed not at the current location but at all the levels specified by path?

My only options at the moment are

a) Create a folder with symlinks to the different source codes and start vim from there

b) Manually add the locations to the vimgrep command after the pattern expression

1

There are 1 best solutions below

0
On

You could implement something like searchsavvy's ListGrep, but instead of doing vimgrepadd on each a:list, you do it recursively on each element in path. Roughly something like this:

...
call setqflist([])
for path in split(&path, ",")
    " Recursively (**) grep each path and add it to quickfix.
    exec 'silent! vimgrepadd/' . a:query . '/gj '. path .'/**'
endfor

Alternatively, you could use the :grep command (probably faster for large trees but needs work for paths with spaces):

function! GrepInPath(query)
    exec ':grep '. a:query .' -R '. join(split(&path, ","), " ")
endf

(Untested.)


If I were you, I'd generate the list of all files every time I sync. You could use csearch and use notgrep and it would work with Unite's file_list source.