Next: , Previous: Nonincremental Search, Up: Search


19.3 Word Search

A word search finds a sequence of words without regard to the type of punctuation between them. For instance, if you enter a search string that consists of two words separated by a single space, the search matches any sequence of those two words separated by one or more spaces, newlines, or other punctuation characters. This is particularly useful for searching text documents, because you don't have to worry whether the words you are looking for are separated by newlines or spaces.

M-s w
If incremental search is active, toggle word search mode (isearch-toggle-word); otherwise, begin an incremental forward word search (isearch-forward-word).
M-s w <RET> words <RET>
Search for words, using a forward nonincremental word search.
M-s w C-r <RET> words <RET>
Search backward for words, using a nonincremental word search.

To begin a forward incremental word search, type M-s w. If incremental search is not already active, this runs the command isearch-forward-word. If incremental search is already active (whether a forward or backward search), M-s w switches to a word search while keeping the direction of the search and the current search string unchanged. You can toggle word search back off by typing M-s w again.

To begin a nonincremental word search, type M-s w <RET> for a forward search, or M-s w C-r <RET> for a backward search. These run the commands word-search-forward and word-search-backward respectively.

A nonincremental word search differs slightly from the incremental version in the way it finds a match: the last word in the search string must be an exact match for a whole word. In an incremental word search, the last word in the search string can match part of a word; this allows the matching to proceed incrementally as you type.