In spacemacs, search occurances of pattern A only in files with name matching pattern B
Asked Answered
V

1

8

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.

Virgy answered 25/9, 2017 at 23:46 Comment(0)
C
6

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>

Citronellal answered 26/9, 2017 at 8:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.