Emacs: Search / Highlight Word

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.

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

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.

List Matching Lines

Alt+x occurAlt+s o】 → same as list-matching-lines

emacs list-matching-lines occur 2014
emacs list-matching-lines (alias of occur)

You can also delete matching lines, sort lines, etc. See: Emacs: List/Delete/Highlight Matching Lines, Sort/Reverse Lines.

Highlighting Commands

The following will highlight until you close the file.

Right Click to Highlight Words

Emacs: Setup Mouse Click to Highlight Matching Words

Search Text in Files

Emacs: Search Text in Files

Find Replace

Emacs: Find and Replace Commands

Find and Replace Topic

  1. Search / Highlight Word
  2. Search Text in Files
  3. Find and Replace Commands
  4. Find Replace Text in Directory
  5. Regex Tutorial
  6. isearch Current Word
  7. xah-find.el, Find Replace in Pure Elisp
Patreon me $5 patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboard for Emacs

If you have a question, put $5 at patreon and message me.