11

In Vim, if I want search for all variable names LX where X is a number, I can simply type /L\d. However, this doesn't seem to work with evil.

Is there another syntax for regular expressions in Evil mode, or will I have to fall back on some Emacs functionality for search and replace using regular expressions?

I am using spacemacs, and I am pretty clueless regarding most things in Emacs, happily staying in Evil mode all day :).

3
  • Where are you trying to search? In a document or in emac's global variables?
    – Jules
    Oct 4, 2016 at 20:37
  • I am searching in a text document
    – user9809
    Oct 4, 2016 at 20:37
  • Are you using isearch or something like helm-swoop or swiper? The last two should be able to do what you want easily. If you want to use the normal isearch function but want to use a different regexp engine look at github.com/benma/visual-regexp-steroids.el
    – Jules
    Oct 4, 2016 at 20:43

1 Answer 1

8

evil uses the Emacs regexp facilities under the hood. Unfortunately, Emacs does not appear to have a separate syntax class for digits, and does not recognize the \d regexp class.

So, to match your variable named LX where X is a digit, it looks like you're stuck with the clunky /L[0-9] or the even clunkier /L[[:digit:]].

Note that, in principle, it looks like you could use character codes as listed by describe-categories:

`\cc`

matches any character whose category is *c*.  Here *c* is a
character that represents a category: thus, 'c' for Chinese
characters or 'g' for Greek characters in the standard
category table. You can see the list of all the currently
defined categories with `M-x describe-categories RET`. You can
also define your own categories in addition to the standard
ones using the `define-category` function (see Categories).

According to describe-categories, digits are category 6. Hence, /L\c6 should work (although it doesn't for me, even though other categories do). Still, you wouldn't be saving yourself much awkward typing when compared to /L[0-9].

1
  • Thank you very much! Think I can live with the clunky syntax for now. Just happy to search replace in a more conveniently way again, and I just tested that it even works with capture patterns, yay!
    – user9809
    Oct 4, 2016 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.