4

I can't find out how to search in Vim in all directories with:

  • grep
  • ack
  • findstring
  • vimgrep

p.e. search "search-item" in all .txt files in c:\ and d:\ (including sub directories)

Can anyone help me?

Reman
  • 7,931
  • 11
  • 55
  • 97

2 Answers2

7

You can use grep as usually

:grep -R 'search-item' path1 path2

For more information see:

:h grep
Ajnasz
  • 115
  • 4
  • this way works much better for me than vimgrep. vimgrep locks up my vim session and seems very slow. – Adamski Jan 15 '15 at 16:12
5

Following works for me

:vimgrep /<search>/ {c:,d:}/**/*.txt
Lieven Keersmaekers
  • 57,207
  • 13
  • 112
  • 146
  • 2
    You can write more then one pattern for `:vimgrep`. Also try `vimgrep // {c:,d:}/**/*.txt` or even `vimgrep // [cd]:/**/*.txt`. – ZyX Dec 25 '11 at 17:22
  • 1
    @ZyX - Thank you, I had no idea. I've incorporated your comment into my answer. – Lieven Keersmaekers Dec 26 '11 at 11:58
  • I thought this was the solution but I noted that it freezes vim. I have to use ctrl-c to unfreeze my vim. – Reman Dec 30 '11 at 20:18
  • @Remonn - the command works allright but perhaps a bit slow on two drives? What happens if you try it on a smaller map? – Lieven Keersmaekers Dec 31 '11 at 11:28
  • @Lieven, partially found it. I can search a sub directory when I put only one '*' in the path: c:/*/*.txt it doesn't work when I put [cd] or {c:,d:} before /*/*.txt or /**/*.txt (I'm using windows can that be the problem?) – Reman Dec 31 '11 at 13:35
  • @Remonn - to be honest, I didn't try the suggestion ZyX proposed, I can only vouch for my original edit. You could be right that this is a windows problem. – Lieven Keersmaekers Dec 31 '11 at 15:22
  • @ZyX - In case you are reading this, could you shine your light on this. Your knowledge of Vim would be much appreciated. – Lieven Keersmaekers Dec 31 '11 at 15:23
  • @Lieven I only know that `vimgrep // c:/**/*.txt d:/**/*.txt` must work and other my solutions *can* (that is why I said “try”, not “you can also use”). I can’t say anything more: at this time wine environment I use to test win32 vim was purged out (and it was purged more then a week ago). – ZyX Dec 31 '11 at 16:37