1

How to make C-s (isearch-forward) and C-r (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?

  • 1
    For 2) see section "Position of the Cursor after Searching" here emacswiki.org/emacs/IncrementalSearch – andrej Nov 29 '18 at 10:38
  • Please post two separate questions for your two separate question. As it stands now, the question is too broad and may be deleted. – Drew Nov 29 '18 at 18:06
3

You can either toggle word-search-mode by doing M-s w after starting isearch, or you can use start in word search mode directly using isearch-forward-word, also bound to M-s w.

  • I tried it first, but unfortunately, it doesn't seem to have an equivalent isearch-backward-word. And it only shows the first matched word, with no way (apparently) to go to the next match. – Bite Bytes Nov 29 '18 at 16:08
  • 2
    isearch-backward-word doesn't exist, but you can do C-r M-s w, or write it and choose your own binding. Once you're in word mode you can just use C-s or C-r to go to the next match. – rpluim Nov 29 '18 at 16:28
2

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, isearch-forward-regexp, or C-M-s, and also the reverse isearch-backward-regexp and 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 er with er\b.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.