Emacs: Search Text in Current File
This page shows you how to use search and highlight features in emacs.
The most useful one is “isearch”.
Interactive search text in current buffer.
While in isearch prompt:
- Ctrl+s → Jump to next occurrence
- Ctrl+r → Jump to previous occurrence.
- Ctrl+g → Exit and place cursor at original position.
- Enter → Exit and place cursor at current position.
How to make case sensitive in isearch?
By default, search is not case sensitive unless your search string contains Capital Letter.
While in isearch, press Alt+s c to toggle search case-sensitivity.
toggle-case-fold-search before isearch. Remember to toggle it back.
Search Word Under Cursor
While in isearch, press Ctrl+w to select more strings to the right of cursor.
The following commands do isearch but uses the word the cursor is on, saves you typing.
- Search the “symbol” under cursor, with boundary check.
- Search the word under cursor, with boundary check.
- Same as isearch but with boundary check.
- Boundary check means, if current word or symbol is “xy”, it will not find “xy2”.
- Emacs “word” usually means alphanumeric with hyphen. “symbol” means programing language's identifier. Whether LOW LINE _ or HYPHEN-MINUS - is part of “symbol” or “word” depends on current syntax table, which is usually different in different major modes.
isearch has many complex features. You can read about them by:
I don't recommend using them because they are very complex. If you need regex search, use
[see Emacs: List/Delete Matching Lines, Sort Lines]
Emacs Find Replace
Put $5 at https://www.patreon.com/xahlee , or goto paypal.com and pay to Xah@XahLee.org . Message me on XahLee discord, say so, ask me questions.
Or Buy Xah Emacs Tutorial