Emacs: Search / Highlight Word
This page shows you how to use search and highlight features in emacs.
The most useful one is “isearch”.
isearch-forward 【Ctrl+s】 → interactive search.
While in isearch:
- 【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.
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.
isearch-forward-symbol-at-point【Alt+s .】 → Search the “symbol” under cursor, with boundary check.
isearch-forward-word【Alt+s w】 → search the word under cursor, with boundary check.
isearch-forward-symbol【Alt+s _】 → 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.
Search Current Word Without Boundary Check
isearch has many complex features. You can read about them by:
I don't recommend using them. If you need regex search, use Alt+x
List Matching Lines
occur 【Alt+s o】 → same as
You can also delete matching lines, sort lines, etc. See: Emacs: List/Delete/Highlight Matching Lines, Sort/Reverse Lines.
The following will highlight until you close the file.
highlight-symbol-at-point【Alt+s h .】
highlight-lines-matching-regexp【Alt+s h l】
highlight-phrase【Alt+s h p】
highlight-regexp【Alt+s h r】
unhighlight-regexp【Alt+s h u】
Right Click to Highlight Words
Search Text in Files
Find and Replace Topic
If you have a question, put $5 at patreon and message me.