Emacs multi-occur Search All Occurrences and List Search Results

There are different ways to perform search in Emacs, each for different purposes and scenarios. The small range search usually interactive, which means the search goes interactively like most people get used to, search one match and go next, one by one.

This usually the case for small file, search for a few occurrences. But search can also be large scale, with dozens of matches, across several buffers and files, list all occurrences for later inspection. You can also call it batched search. Both are useful for us. In command line, we usually use tool like grep to do the job. Sometimes we want to do the same thing in Emacs. And Emacs provides a lot of choices for us.

multi-occur

Suppose you have a large file opened in Emacs. Even though for most people, small text file is common situation in their daily editing life, but there are cases that people have to deal with large text file and Emacs can handle it without problem, actually many average text editors were not designed for processing large text file, using them in this situation will be painful.

In Emacs I can put all my blog posts or articles in one text file and navigate through them or locate the things I want to edit easily. I can load a big list of item into Emacs and find or edit things I needed easily. Because Emacs provided with us ample of handy search facilities.

To find and edit things efficiently in those kind of situations, multi-occur is a must have command.

Execute M-x multi-occur, it will prompt you to select buffers that will be searched, press enter to select the first in candidates, press enter to select the next and so on, after selection press Ctrl-J to end the selection.

Then you can input the regular expression to conduct the search. For example the title starts with double brackets [[ and ends with ]], to list all title in the buffer you can input the regular expression

 
^\[\[
 

The search results is displayed in a new buffer, you can click the item or press Ctrl-M to jump to the line in the buffer.