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.

Dmitry
  • 213
  • 1
  • 7

1 Answers1

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

Tyler
  • 21,719
  • 1
  • 52
  • 92
  • 1
    Yes, I can confirm it works. – Manuel Uberti Nov 04 '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. – Dmitry Nov 04 '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 http://www.emacswiki.org/emacs/EmacsSyntaxTable or http://emacs.stackexchange.com/questions/9583/how-to-treat-underscore-as-part-of-the-word/9584#9584 – Tyler Nov 04 '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 02 '18 at 08: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 02 '18 at 13:51
  • @Tyler \b doesn't work for me, but `\_` works. – CodyChan May 03 '18 at 01:35
  • @CodyChan `\b` works for words, `\_<` works for symbols, so that's a hint about details you're not providing. Please open a new question if you want more help – Tyler May 03 '18 at 13:37