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?
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.
\(=\)\@<!=\(=\)\@!
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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.