Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Is there a way to allow \w inside character sets in vim regex?




Sorry this is quite a simple question but I am unable to google for it effectively.

Basically, I expect :s/\v\w+/foo/ to behave the same as :s/\v[\w]+/foo/ but the latter that puts \w within a character set does not match anything.

Is there a flag to enable this? is this not supported?

Thanks and sorry for the simplistic question. by the way, I know about [:alnum:] and things or that I could use [a-zA-Z] or something similar (possibly with underscores, I can't remember), but was looking for a way of using one consistent, quick notation.

like image 822
Mike H-R Avatar asked Mar 19 '23 13:03

Mike H-R

1 Answers

No, you can't. You'll find that information at :help /[, actually near :help /\]:

  - The following translations are accepted when the 'l' flag is not
    included in 'cpoptions' {not in Vi}:
    NOTE: The other backslash codes mentioned above do not work inside

The equivalent collection for \w is [_[:alnum:]]. You can also combine \w with a collection, like this: \%(\w\|[...]\).

like image 165
Ingo Karkat Avatar answered Apr 24 '23 21:04

Ingo Karkat