Delete anything other than pattern

前端 未结 3 1430
时光说笑
时光说笑 2020-12-30 04:50

Let\'s say this is my text:

this is my text this
is my text this is my text
my text is this

I would like to highlight all text ex

3条回答
  •  天涯浪人
    2020-12-30 05:28

    I've implemented Benoit's clever regular expression as a custom :DeleteExcept command in my PatternsOnText plugin. It offers other related commands like :SubstituteExcept or :SubstituteInSearch, too.

    OP's example would be

    :%DeleteExcept /text/
    

    Comparing that with @Benoit's explicit command (:%s/\(^\|\(text\)\@<=\).\{-}\($\|text\)\@=//g), it's a lot simpler.

提交回复
热议问题