Emacs: Search Text in Buffer

By Xah Lee. Date: . Last updated: .

This page shows you how to use search and highlight features in emacs.

The most useful one is “isearch”.

Alt+x isearch-forwardCtrl+s】 → interactive search.

emacs isearch 2016-11-02
emacs isearch. 【Ctrl+s

While in isearch:

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.

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 strings to the right of cursor.

The following commands do isearch but uses the word the cursor is on, saves you typing.

Note:

  1. Boundary check means, if current word or symbol is “xy”, it will not find “xy2”.
  2. 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

Emacs: isearch Current Word

Emacs Isearch Whitespace Regex

Emacs Isearch Whitespace Regex

isearch Keys/Modes

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

[see Emacs: List Highlight Delete Matching Lines, Sort Reverse]

Emacs Find Replace

  1. Search Text in Buffer
  2. isearch Current Word
  3. Isearch Whitespace Regex
  4. Highlight Text in Buffer
  5. List Delete Highlight Sort Lines
  6. Search Text in Directory
  7. Find Replace in Buffer
  8. Find Replace in Directory
  9. xah-find.el, Find Replace in Pure Elisp
  10. Regex Tutorial

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs

Emacs

Emacs Lisp

Misc