Wiki

by yszheda

View project onGitHub

Tip 73: Use the \v Pattern Switch for Regex Search

Return to the top: <<Practical Vim>>

Find Hex Colors with Magic Search

Using magic search, we have to escape (,),|, and { characters to confer special meaning upon them.

/#\([0-9a-fA-F]\{6}\|[0-9a-fA-F]\{3}\)

Find Hex Colors with Very Magic Search

Using the \v pattern switch, the (,),|, and { characters assume special meaning.

/\v#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})

References:

# If you open the file in vim,
# then you can \"ayy@a the next line to execute the vim command: 
:h \v

Use the Hex Character Class to Further Refine the Pattern

We can compact the expression further by using the \x character class, which stands for [0-9a-fA-F].

/\v#(\x{6}|\x{3})

References:

# If you open the file in vim,
# then you can \"ayy@a the next line to execute the vim command: 
:h /character-classes