Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs - multiline search

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 ?

like image 504
nha Avatar asked Oct 19 '25 05:10

nha


1 Answers

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:

  1. In a Dired buffer, mark some files you want to search, then hit A.

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

like image 161
Drew Avatar answered Oct 21 '25 12:10

Drew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!