Reputation: 3953
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
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
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
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