Mike H-R
Mike H-R

Reputation: 7815

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.

Upvotes: 4

Views: 135

Answers (1)

Ingo Karkat
Ingo Karkat

Reputation: 172600

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\|[...]\).

Upvotes: 7

Related Questions