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”.

emacs main search command
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.

Make Space Hyphen Lowline Equivalent

You can set isearch so that typing space will also search for - and _ and newline.

Put this in your emacs init file:

;; for isearch-forward, make these equivalent: space newline tab hyphen underscore
(setq search-whitespace-regexp "[-_ \t\n]+")

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.

emacs search commands
Alt+s .isearch-forward-symbol-at-pointSearch the “symbol” under cursor, with boundary check. That is, “xyz” does not match “xyz2”. What chars are part of “symbol” depends on major mode. [see Emacs 24.4 New Features (released 2014-10)]
Alt+s wisearch-forward-wordsearch the word under cursor, disregard differences of {LOW LINE _, hyphen -, space }, but also with boundary check. That is, “x y” does not match “x y2”.
Alt+s _isearch-forward-symbolSame as isearch but with boundary check.


  1. These isearch commands do boundary check. If current word is “xy”, it will not find “xy2”.
  2. 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 Keys/Modes

isearch has many complex features. You can read about them by:

Isearch Current Word Without Boundary Check

For a command to isearch current word without boundary check, see:

Emacs: isearch Current Word

List Matching Lines

Sometimes you want to list the lines matching a regex.

emacs highlight commands
Alt+s ooccursame 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, …. See: Emacs: List/Delete/Highlight Matching Lines, Sort/Reverse Lines.

Highlighting Commands

isearch will color matched strings, but when you exit isearch, the coloring will go away.

The following will highlight until you close the file.

emacs highlight commands
Alt+s h .highlight-symbol-at-point
Alt+s h lhighlight-lines-matching-regexp
Alt+s h phighlight-phrase
Alt+s h rhighlight-regexp
Alt+s h uunhighlight-regexp

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. Emacs: Search / Highlight Word
  2. Emacs: Search Text in Files
  3. Emacs: Find and Replace Commands
  4. Emacs: Find Replace Text in Directory
  5. Emacs: Regex Tutorial
  6. Emacs: isearch Current Word
  7. Emacs: xah-find.el, Find Replace in Pure Elisp
Like my tutorial? Put $5 at patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboard for Emacs

Ask me question on patreon