1

I am using the :vim COMPANY_ID ~/Projects/creditdutile/loanrabbit/* | cw command to look for the word COMPANY_ID in the loanrabbit directory. However, that command look for just for file I guess, not in subdirectories. How could I make a global research with that command?

3

I assume you're invoking that command from inside Vim. You can use ** to search a directory tree. i.e.

:vimgrep COMPANY_ID ~/Projects/creditdutile/loanrabbit/** | cw

See :h starstar-wildcard for the full documentation on **. Also note that you can use ** as part of a path. For example I often search some templates with:

:vimgrep h1 temp**/*.html

and it matches both templates/foo.html and temp/extra/templates/bar.html


Shameless marketing: we have a Vi & Vim stack exchange community

  • 1
    I have absolutely no idea why this site doesn't point every single vim question at the vim site. – user13757 Feb 16 '17 at 17:15
  • @DrEval - There are some good old Vim questions here and on SU too. And many more on SO. Most of them from before the creation of vi.SE . We are struggling a little with not enough marketing of the site on vi.SE :) . Directing Vim users to vi.SE must be the solution to that. – grochmal Feb 16 '17 at 17:24
  • Your answer is good, but has got certain limit. In loanrabbit, I have files and subdirectories. :vimgrep COMPANY_ID ~/Projects/creditdutile/loanrabbit/** | cw looked inside subdirectories, but not inside files from loanrabbit. Could you tell me how could I pass through all files and subdirectories inside loanrabbit? – J.Doe Feb 16 '17 at 17:57
  • @J.Doe - I'm pretty confident that the starstar does match both files and directories in that scenario. Yet, If i'm not mistaken, there was a bug with the ending / at some point. You may be using that version (i'm using v8.0.329). In any case, loanrabbit** instead of loanrabbit/** should go around that issue (may cause issues if you have another directory named, e.g. loanrabbit.old though). – grochmal Feb 16 '17 at 18:49
1

I am having some trouble understanding the question, but grep -nr "COMPANY_ID" ~/Projects/creditdutile/loanrabbit/ should be a nice way of searching for the word COMPANY_ID in all files in that directory and any sub-directories.

If you are trying to do this from vim then you almost had it :vimgrep ~/Projects/creditdutile/loanrabbit/** | cwshould do it. The asterisks allow you to search throughout the directory.

0

use the grep command

grep -r "COMPANY_ID" ~/Projects/creditdutile/loanrabbit/
  • Sorry, but according to me, grep is the low range of :vim. This is not my question. – J.Doe Feb 16 '17 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.