开发者

Vim search for a pattern and if NOT occurs delete line

开发者 https://www.devze.com 2022-12-09 13:15 出处:网络
I\'ve read this question, but I want to know ho开发者_如何学Cw can I delete the line when the pattern DOESN\'T occur.Deleting the rest of the line when a pattern does not occur is ... hard for me to u

I've read this question, but I want to know ho开发者_如何学Cw can I delete the line when the pattern DOESN'T occur.


Deleting the rest of the line when a pattern does not occur is ... hard for me to understand.

Did you mean, delete the whole line if it doesn't have a pattern?

:v/pattern/d

If you meant, preserve the line but clobber the characters:

:v/pattern/s/.*//


Equivalently:

:g!/pattern/d

Easier to remember in my opinion, because! is ingrained as "not" in my brain.


:v/pattern/s/.*//
0

精彩评论

暂无评论...
验证码 换一张
取 消