2

For example when I'm trying to find and replace something using

g/[:digit:]/s/1/2/g

Vim showing error: Pattern not found: [:digit:], while the string contains digits.

Following POSIX Bracket Expressions are not working: [:digit:], [:xdigit:], [:upper:], [:lower:], [:print:], [:cntrl:]

At the same time all the others POSIX Bracket Expressions (like [:alnum:], [:alpha:], [:blank:] etc. work pretty well.

Vim version 7.4

1

1 Answer 1

2

The [:foo:] bracket expression is meant to be used inside a [...] collection, like this:

:g/[[:digit:]]/s/1/2/g

This allows you to specify multiple (alternative; otherwise it would be concatenation) groups, and mix with other characters, e.g.: [[:space:][:digit:]abc].

2
  • Thanks a lot, it works! But why some bracket expressions require that so called [:foo:] bracket expression, while others don't?
    – Alexander
    Feb 3, 2015 at 14:08
  • 1
    I think you just got false positives from those. Feb 3, 2015 at 16:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .