0

I did the following tests:

code output notes
:echo substitute("s s", '\v[^s]', "<&>", "g") s< >s space replaced. All fine
:echo substitute("s s", '\v[^\s]', "<&>", "g") s< >s [^\s] is the same as [^s]! ??
:echo substitute("s s", '\v[^ \t]', "<&>", "g") <s> <s> both s replaced

It looks like \s does not work inside [ ] brackets in Vim regular expression.

Is this expected?

Is there any way I can use \s \S inside bracket expressions in Vim?

1 Answer 1

1

You are right the character atom (e.g.: \s, \S, \d, ...) cannot be part of a collection ([])

To get the reference in the doc you can look for the NOTE in the section: :help collection:

NOTE: The other backslash codes mentioned above do not work inside []!

The following answer gives you more details about what is allowed and not allowed in a collection.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.