me2
me2

Reputation: 3953

What is the correct VIM regexp to search to get = but not ==?

In the following code:

a = b = c == 1

I'd like to match on only the first two =, but not the == at the end.

I figured the pattern \<=\> would work since \< matches beginning of word and \> matches the end. But it doesn't. What's wrong with this pattern and what is the correct pattern?

Upvotes: 2

Views: 103

Answers (3)

Ingo Karkat
Ingo Karkat

Reputation: 172648

You cannot use \<=\> because usually, the equals character is not a keyword character. You could fix that with :set iskeyword+==, but that may have side effects for navigating and syntax highlighting.

Upvotes: 4

Explosion Pills
Explosion Pills

Reputation: 191779

vim supports lookarounds, so you can use a negative lookbehind and negative lookahead surrounding the =. This will match only the desired = and even = at the start or end of the line.

\(=\)\@<!=\(=\)\@!

Upvotes: 5

mvp
mvp

Reputation: 116317

This regex should work:

[^=]=[^=]

It will break if you want to match single = at the beginning or at the end of line - but I figured this is not an issue for your patterns.

Upvotes: 0

Related Questions