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?

Drew
  • 75,699
  • 9
  • 109
  • 225
Tony
  • 231
  • 1
  • 4

1 Answers1

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.

  • 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 Apr 09 '15 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. –  Apr 09 '15 at 12:47
  • 2
    Try `isearch-forward-word`, which is bound to `M-s w` in recent Emacs. – politza Apr 09 '15 at 20:36
  • Emacs 23 didn't work for me, make sure you're using 24. – interestedparty333 Jan 29 '16 at 23:40