1

How can I search for text in a files in a directory structure but ignore certain files.

For example, I want to be able to find the text sometext but not search files that match *.gz

sashang
  • 11,704
  • 6
  • 44
  • 58
  • 1
    possible duplicate of [How to exclude file patterns in vimgrep?](http://stackoverflow.com/questions/1898987/how-to-exclude-file-patterns-in-vimgrep) – Amadan Nov 29 '11 at 03:06
  • Maybe you would be more interested in doing a `noautocmd vimgrep` which won't load plugins for those files. This will speed up searches considerably. – Benoit Nov 29 '11 at 12:50

2 Answers2

2

You can do this

vimgrep /sometext/g `find ~ \( -regextype posix-extended -regex '.*py' \) -not path ~/tmp`

There is something called backtick expression, which provides the arguments to vimgrep: http://vimcasts.org/episodes/populating-the-arglist/

Here the find command is being passed as a backtick expression, and find can exclude paths from vigrep.

The actual search term is long, but you dont have to type it all out. I usually just use q: to bring up the previous ex commands, search for the previous find command and modify it for the next search.

alpha_989
  • 4,882
  • 2
  • 37
  • 48
1

I don't think you can specify exclusions using the internal vimgrep. You can, however, include multiple file wildcards so if you can specify all the files you're interested in that way there's no need for exclusion. For example:

vimgrep /sometext/ *.c *.h *.txt 
Herbert Sitz
  • 21,858
  • 9
  • 50
  • 54