13

I am used to writing files where paragraphs are split into several lines, e.g. with fill-column. When I search for a string (C-s) such as this is a long text, the search results would not return the locations where the string appears with a line break between two of the words (like this\nis a long text).

Is there a command that would also return these results?

0

1 Answer 1

13

Take a look at the variables isearch-lax-whitespace, isearch-regexp-lax-whitespace, and search-whitespace-regexp.

If the first two variables are set to something non-nil (e.g. t) any space character in your search string will match any sequence matched by the regular expression defined by the search-whitespace-regexp variable.

To match words across line breaks do this:

;; Make Isearch work across spaces, tabs, and newlines.
(setq isearch-lax-whitespace t
      isearch-regexp-lax-whitespace t
      search-whitespace-regexp "[ \t\r\n]+")

A space character in your query will now match any space, tab, or linebreak any number of times.

4
  • Thanks, but that does not work for me. My Emacs version is 23.4.1. Apparently it does not have an "isearch-lax-whitespace" variable.
    – Tony
    Commented Apr 9, 2015 at 11:57
  • 1
    Yeah, these features were introduced in Emacs 24.3. Any chance of upgrading to a more recent version? Version 23.4.1 is already more than three years old.
    – user2005
    Commented Apr 9, 2015 at 12:47
  • 2
    Try isearch-forward-word, which is bound to M-s w in recent Emacs.
    – politza
    Commented Apr 9, 2015 at 20:36
  • Emacs 23 didn't work for me, make sure you're using 24. Commented Jan 29, 2016 at 23:40

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.