In spacemacs, I often search for patterns within my project via SPC-*
or SPC-/
. These commands allow me to input a pattern to search for, such as the name of a function I would like to jump to the definition of.
Sometimes, I would like to restrict that search to files of only a certain type, such as searching only *.elm
files and omitting all others (*.hs
, *.sql
, etc.).
How can I specify filenames for my pattern search? I.e., How to search for pattern A only in files with name matching pattern B?
I'm wondering if there is some special key I can type as part of my search query to accomplish this.
If you use ag
as a search backend, you can do SPC-/ -G<file name regexp> <search pattern>
, see man ag
for details.
I am not sure if the grep
backend can do something similar, I think the internal call to grep
is much more complex and adding flags tends to hang my emacs session. From a shell you can run grep -n <search pattern> <file pattern>