Search code examples
searchemacs

How do I find all occurrences of a string in emacs?


There is a command that I can give Emacs to find all occurrences of a string in a file. This opens up a buffer so I can browse through them. I forgot what that command is. What is it?


Solution

  • You're probably looking for M-x occur:

    Prompt for a regexp, and display a list showing each line in the buffer that contains a match for it. If you type M-n at the prompt, you can reuse search strings from previous incremental searches. The text that matched is highlighted using the match face. A numeric argument n specifies that n lines of context are to be displayed before and after each matching line.