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.

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

1 Answer 1

6

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).

7
  • 1
    Yes, I can confirm it works. Commented Nov 4, 2015 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. Commented Nov 4, 2015 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/… Commented Nov 4, 2015 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. Commented May 2, 2018 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. Commented May 2, 2018 at 13:51

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.