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
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
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.
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