Is there a module to do multiline search in Emacs ?
I have used grep
, pt
and now ag
, and they are great. But sometimes when exploring a codebase you search for things that are on multiple lines (and therefore get nothing), but reducing the search to fewer words yields a lot of results.
Is there a way to get multiline search in Emacs in a whole project ?
Of course there is. There are multiple ways.
You don't say what kind of search you are trying to do: single file? multiple buffers? regexp? Do you need a fixed list of search hits or do you want incremental search?
Here's one simple answer:
In a Dired buffer, mark some files you want to search, then hit A
.
Type a regexp to match. Use C-q C-j
to enter a newline char to match. Hit RET
to enter the regexp.
That searches through the marked files, stopping at each search hit in turn. Use M-,
to go to the next hit, etc.
For example, to search for doc strings of variable definitions, search with this regexp or similar:
Search marked files (regexp): (defvar.*
.*"Non-nil
There's a newline char after the first .*
, which you enter using C-q C-j
.
There are lots of other ways to search in Emacs. The best place to start is the Search and Replace category of Emacs Wiki. There you can find ways to search broken down by main characteristics and described.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With