4

I wish to search a separate word with helm-swoop. There should be some trick for this I guess. For instance I know that to search 2 words will be like word1\|word2 and to search the end of the line like: endofline$

So does anybody know how to search a whole word only? Thanks.

  • Good question, I didn't realize you could do this until you asked! – Tyler Nov 4 '15 at 15:42
  • Note that $ matches the end of a line, not the end of a word – Tyler Nov 4 '15 at 15:43
  • True, I'll correct that – cy8g3n Nov 4 '15 at 15:46
5

You can use any regexps supported by Emacs, which provides \b as a match for the boundary of a word. So swooping for \bin\b will match in but not input, begin or being.

The full list of Emacs-supported regexps is in the manual (second page).

  • 1
    Yes, I can confirm it works. – Manuel Uberti Nov 4 '15 at 15:37
  • Yes, it works, also if you know how to force it consider this sign '_' as part of the word please let me know. It doesn't consider signs '(', ')' as part of the word what is good, but for C coding emacs should consider '_' as part of the word. Thanks. – cy8g3n Nov 4 '15 at 15:53
  • 1
    The regexps use the syntax table for the current mode. By default, in c-mode _ is treated as a symbol. You can change that with (modify-syntax-entry ?_ "w") in your c-mode hook. See emacswiki.org/emacs/EmacsSyntaxTable or emacs.stackexchange.com/questions/9583/… – Tyler Nov 4 '15 at 17:19
  • This does not work for me. Ubuntu 16.04 Emacs 25.3.2. It seems the "\b" doesn't work at all. – CodyChan May 2 '18 at 8:57
  • @CodyChan \b should work, so if it doesn't for you we're missing some key information. Perhaps you could open a new question and provide a detailed explanation of what you've tried. Otherwise we don't know enough to help you. – Tyler May 2 '18 at 13:51

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.