How to make
isearch-backward) search only for words that start with the argument passed to them, instead of searching for the argument even if it's in the middle of a word?
word-search-mode is the usual way to constrain your searches to words rather than letters, as @rpluim shows.
An alternative, more general approach is to use regular expression searches,
C-M-s, and also the reverse
C-M-r. You can then use a regular expression to limit your search:
\bin will match
in when it occurs at the start of a word.
This is not as convenient as
word-search-mode, but it is more flexible. For instance, you could find words ending with
Here's what I use to do this
;; Use isearch-forward-word by default (treats a space as any whitespace or punctuation) (global-set-key (kbd "C-s") 'isearch-forward-word) ;; This is the same as isearch-forward-word except with the first argument to ;; isesarch-mode set to nil to do reverse search (defun isearch-backward-word (&optional not-word no-recursive-edit) "Do incremental search backward for a sequence of words. With a prefix argument, do a regular string search instead. Like ordinary incremental search except that your input is treated as a sequence of words without regard to how the words are separated. See the command `isearch-forward' for more information. This command does not support character folding, and lax space matching has no effect on it." (interactive "P\np") (isearch-mode nil nil nil (not no-recursive-edit) (null not-word))) (global-set-key (kbd "C-r") 'isearch-backward-word)
isearch-backward-word doesn't exist so I just copied the source of
isearch-forward-word and changed the first argument of
nil to do reverse isearch.