When searching using:
C-s SPC SPC
Also matches single spaces. I want to match exactly two space.
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.Sign up to join this community
M-s SPC during Isearch to toggle matching whitespace literally. When matching literally, each
SPC char you type is matched individually. (This used to be the default Emacs behavior, BTW.)
To configure this as the default behavior customize option
M-x customize-option search-whitespace-regexp.)
See the GNU Emacs manual, node
C-h v search-whitespace-regexp tells us this (showing the default value):
search-whitespace-regexpis a variable defined in
Its value is
nil, regular expression to match a sequence of whitespace chars.
When you enter a space or spaces in the incremental search, it will match any sequence matched by this regexp. As an exception, spaces are treated normally in regexp incremental search if they occur in a regexp construct like
If the value is a string, it applies to both ordinary and regexp incremental search. If the value is
nilfor ordinary incremental search, or
nilfor regexp incremental search, then each space you type matches literally, against one space.
You might want to use something like
"[ \t\r\n]+"instead. In the Customization buffer, that is
[followed by a space, a tab, a carriage return (control-M), a newline, and
You can customize this variable.
This variable was introduced, or its default value was changed, in version 24.3 of Emacs.
Using regexp search helps, but you can also make sure of literal spaces for the search using C-q SPC to quote a space into the search.
To riff off of @Rovanion's answer then, using
C-M-s C-q SPC C-q SPC
That will search for two consecutive spaces. Interestingly,
isearch-forward-regexp requires discrete matches. Searching
aa will only match once and not again at the second character.