Is there a way to do negative lookahead in vim regex?

后端 未结 5 1718
一生所求
一生所求 2021-01-31 15:40

In Vim, is there a way to search for lines that match say abc but do not also contain xyz later on the line? So the following lines would match:

<
5条回答
  •  时光说笑
    2021-01-31 15:54

    I think I'd write this as /abc\(\(xyz\)\@!.\)*$

    I'm not sure whether this is faster than other suggestions (I think it might be since it tests each position only once) but it makes conceptual sense as:

    "abc followed by anything which is not xyz, any number of times until end of line"

    I like that better than "abc followed by anything not followed by xyz" as in the other patterns mentioned.

提交回复
热议问题