I want to be able to search for some text and navigate quickly between the occurrences. What is a convenient way to search for some text, view all the occurrences, and jump quickly to the next/previous occurrence?
The manual is your friend!
The basic search capability is incremental search. Press
C-s and enter the string to search (
C-r to search backwards). Press
C-r again to go to the next/previous occurrence. Any command other than typing text, backspace and a few others exits search mode; in particular, press
RET to continue editing where the occurrence was found or
C-g to go back to the starting point.
C-s C-s to repeat the previous search (
C-r C-r to repeat it backwards). After entering incrementatl search mode with
M-n to browse the search history (previous/next). Press
C-s C-w to search for the word under the cursor (and other similar commands).
C-M-r to search for a regular expression instead of a string.
If you want an overview of all the occurrences of a string (or more generally a regular expression),
M-x occur is your friend. It shows a list of matching lines in a separate buffer. In the
*Occur* buffer, press
RET or the middle mouse button to jump to the corresponding line in the original buffer. See the manual for commands that search multiple buffers.
Instead of just providing a link to the manual section section about searching, the real "the manual is your friend" answer is to tell you how to look this up in the manual yourself:
C-h r i searching RET or
C-h r i search TAB ing RET.
If someone is really at this basic a level with Emacs, then the real question is how to look something up in the manual, and the answer is
C-h r i.
Emacs is self-documenting. Start by asking Emacs, not Stack Exchange. To learn to ask Emacs, start with
Press Ctrl+S (
isearch-forward), then type your text. Emacs will search as you type. To find the next occurrence, press Ctrl+S again. To go to previous occurrence, press Ctrl+R. To stop, press Enter ↵ to leave the cursor there. Or type Ctrl+G to return to the spot before search was started.
This command is also under the menu Edit.
Ctrl+S twice will search your last searched word.