Often I'll search (an ordinary i-search) for a sequence of two spaces, or three, or four.

But on one machine I'm using, emacs by default appears to be in some mode where searches for spaces are special. For example, a search for two spaces will "find" a tab — I guess because a tab "looks like" two (or more) spaces.

Does anyone know what this mode might be, or how to turn it off? (Whatever the mode is, it's active even in Fundamental mode.)

I'm observing this with emacs 24.3.1. I do not observe it with 22.1.1 or 26.1. But I suspect it's a configuration thing, not a version-specific thing.


1 Answer 1


A SPC char normally matches all whitespace defined by option search-whitespace-regexp. You can customize this option, so you get the matching you want by default. C-h v search-whitespace-regexp tells us, in addition to more info about the option:

If the value is nil, or [if] isearch-lax-whitespace is nil for ordinary incremental search, or isearch-regexp-lax-whitespace is nil for regexp incremental search, then each space you type matches literally, against one space.

Use key M-s SPC during Isearch to toggle this behavior. C-h k M-s SPC says:

isearch-toggle-lax-whitespace is an interactive compiled Lisp function in isearch.el. ? (isearch-toggle-lax-whitespace)

Toggle lax-whitespace searching on or off.

In ordinary search, toggles the value of the variable isearch-lax-whitespace. In regexp search, toggles the value of the variable isearch-regexp-lax-whitespace.

You can of course set the default values of those individual variables (they're not user options, however), to define the default behavior you prefer. But a mode etc. can change their values, overriding the values you set. (And a mode can change the value of search-whitespace-regexp, though modes are generally not supposed to override user options.)

At least you can toggle the behavior at any time.

If you are seeing this only for Emacs version 24.3.1, do you also see the problem if you start that Emacs version using emacs -Q (no init file)? If not then bisect your init file to find the culprit.

Not-so-well-known tip:

When regexp isearching, you can use C-q SPC to search for a single space char at a time. No need to fiddle with any lax/strict whitespace matching.

  • Excellent. Thanks very much. Oddly, emacs -Q didn't help. Commented Mar 11, 2022 at 21:40
  • But the relevant setq's are in my .emacs now, and all is right in the world again (with respect to whitespace searches, anyway :-) ). Commented Mar 11, 2022 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.