Search code examples
regexvim

Vim: How do I search for a word which is not followed by another word?


Pretty basic question, I'm trying to write a regex in Vim to match any phrase starting with "abc " directly followed by anything other than "defg".

I've used "[^defg]" to match any single character other than d, e, f or g.

My first instinct was to try /abc [^\(defg\)] or /abc [^\<defg\>] but neither one of those works.


Solution

  • Here's the search string.

    /abc \(defg\)\@!
    

    The concept you're looking for is called a negative look-ahead assertion. Try this in vim for more info:

    :help \@!