Emacs: Search Text in Current File
isearch, Interactive Search
The most useful one is “isearch”.
isearch-forward
【Ctrl+s】-
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.
Case Sensitivity in Isearch
By default, search is Case-Insensitive unless your search string contains Capital Letter.
While in isearch, press Alt+s c to toggle search case-sensitivity.
Or, Alt+x toggle-case-fold-search
before isearch. Remember to toggle it back.
Search Word Under Cursor
While in isearch, press Ctrl+w to select more words to the right of cursor.
The following commands do isearch but use the word under cursor.
isearch-forward-symbol-at-point
【Alt+s .】-
Search the “symbol” under cursor, with boundary check.
Boundary check means, if current word or symbol is “xy”, it will not find “xy2”.
isearch-forward-word
【Alt+s w】-
Search the word under cursor, with boundary check.
- Emacs WORD usually means alphanumeric and 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 set by Major Mode
isearch-forward-symbol
【Alt+s _】- similar to isearch but with boundary check.
isearch Keys
isearch has many complex features. You can read about them by:
- Alt+x
isearch-describe-mode
- Alt+x
isearch-describe-bindings
I don't recommend using them because they are very complex. If you need regex search, use
Alt+x list-matching-lines
〔see Emacs: List Matching Lines〕
Emacs Find Replace
- Emacs: Search Text in Current File
- Emacs: Search Current Word 🚀
- Emacs Init: isearch Whitespace Regex
- Emacs Init: isearch by Arrow Keys
- Emacs: Highlight Word, Line
- Emacs: List Matching Lines
- Emacs: Search Text in Directory
- Emacs: Find Replace in Current File
- Emacs: Interactive Find Replace Text in Directory
- Emacs: Xah Find Replace (xah-find.el) 📦
- Emacs: Regular Expression