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 communityWhen searching using:
C-s SPC SPC
Also matches single spaces. I want to match exactly two space.
Use 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 search-whitespace-regexp
to nil
. (M-x customize-option search-whitespace-regexp
.)
See the GNU Emacs manual, node Special Isearch
.
(set-variable 'search-whitespace-regexp nil)
in there. Thanks.
– Gray
Mar 28 '18 at 13:49
set-variable
doesn't save the new value persistently, so that won't change the default behavior. I think M-x customize-option
is what is called for here.
– Drew
Mar 28 '18 at 23:57
Using regexp incremental search solves the problem, if you escape the space characters:
C-M-s \SPC\SPC
You can also use search and replace without the backslashes, if that's what you're after:
M-% SPC SPC
ESC C-s
instead. See also github.com/leoliu/ggtags/issues/64
– Jonas Dahlbæk
Mar 16 '17 at 19:57
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 isearch-forward-regexp
:
C-M-s C-q SPC C-q SPC
That will search for two consecutive spaces. Interestingly, isearch-forward-regexp
requires discrete matches. Searching aaa
for aa
will only match once and not again at the second character.