Patrick
Patrick

Reputation: 181

vim search a decimal but mismatch some other number

When I use the vim to search a decimal(/0.03), like 0.03, in a text file, it will match not only the 0.03 but also the numbers such as 0403.

What should I use to replace the search equation?

Upvotes: 1

Views: 1709

Answers (3)

DJMcMayhem
DJMcMayhem

Reputation: 7689

Since nobody else has mentioned it, you can also use the "nomagic" option. This signals to vim regex to treat meta characters, such as ., ^, and $ as literal characters.

/\V0.03

Will do what you're looking for. \V means no magic.

There's also "very magic" \v which treats regular characters like (), <>, and | as meta characters.

Upvotes: 1

user3363247
user3363247

Reputation: 76

The dot is being interpreted as "a single arbitary character" as it is in regular expressions.

Escape the dot with the reverse slash, e.g. "0\.03" to match the literal dot symbol.

Upvotes: 5

ThomasRSkinner
ThomasRSkinner

Reputation: 126

You need to search for 0\.03 by escaping the decimal point. Otherwise vim interprets the . as "any character" eg 4

Upvotes: 1

Related Questions