I am struggling combining a negative lookahead assertion @! with the very magic specifier \v

I have a buffer with this content

<div class='vvv'>abc</div>
<div class='ttt'>abc</div>

and I want to search for all classes except vvv. I can do this like so


This finds the second line (class='ttt'), as expected. Yet, when I try to search with the very magic modifier:


the search finds both classes. I had wrongly assumed these searches to be equivalent. Why are they different?

  • 4
    be carefull with\= – JJoao Oct 3 '15 at 14:07
  • My earlier comment was just ignorant, sorry. JJoao is quite right: the second, very magic pattern needs to be \vclass\=.(vvv)@!. – Peter Lewerin Oct 3 '15 at 15:13
  • 1
    @JJoao you might want to turn your comment along with Peter's comment into an answer, so that I can accept it. – René Nyffenegger Oct 3 '15 at 18:02

The code you wrote is perfect but in \v mode = needs protection.


In normal mode \= means optional (the same as \?). In \v mode, = means optional: class= ends up meaning class|clas (I would prefer = were just a normal char).

So, to mark the classes different form ttt we can:


When we have more complex "different-from" patterns it may be easier the long way:

:%s/\vclass\='(tt1|...)'/classAUX=\1/          rename exceptions
:%s/\vclass\='.{-}'/MARKED&/                   treat normal cases
:%s/\vclassAUX/class/                          unrename

\thanks{Peter Lewerin}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.