简体   繁体   English

Vim替换:在指定的单词之间删除所有

[英]Vim substitute: Delete All between specified words

A piece of the file I am trying to cut 我试图削减的一块文件

HTMName=[...] owns the means of production. Proletariat do not and sell their labor power.
HTMFile=x
ClickPlay=0
TestElement=0

Type=HTML
Cors=123
DisplayAt=215
Hyperlink=0
HTMName=Bourgeois
HTMFile=x
ClickPlay=0

End result 最终结果

[...] owns the means of production. Proletariat do not and sell their labor power.
Bourgeois

I am aware that the top and bottoms of the file will have remainders. 我知道文件的顶部和底部将有剩余部分。 I have tried the following 我尝试了以下内容

:s%/^\sHTMFile[\s\S]*\n\s*HTMName=$//g

And many other variations which all return no pattern found. 还有许多其他变化都没有找到任何模式。 My grasp of regex is pretty weak. 我对正则表达式的掌握非常微弱。

At first, I would delete all lines which don't contain the searched pattern ( HTMName= at the start of the line), and then I would remove the searched pattern 首先,我将删除所有不包含搜索模式的行( HTMName=在行的开头),然后我将删除搜索的模式

:v/^HTMName=/d
:%s///

:v means execute a command (in this case ":d") on the lines where {pattern} (in this case "HTMName=" at the start of the line) does NOT match. :v表示在{pattern}(在这种情况下,行的开头“HTMName =”)不匹配的行上执行命令(在本例中为“:d”)。

:d means delete lines. :d表示删除行。

See more in help: 在帮助中查看更多:

PS: If your pattern is not in just one line, you can try PS:如果您的模式不在一行中,您可以尝试

:%s/^HTMName=\(\_.\{-}\)HTMFile=\|.*/\1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM