簡體   English   中英

Vim替換:在指定的單詞之間刪除所有

[英]Vim substitute: Delete All between specified words

我試圖削減的一塊文件

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

最終結果

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

我知道文件的頂部和底部將有剩余部分。 我嘗試了以下內容

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

還有許多其他變化都沒有找到任何模式。 我對正則表達式的掌握非常微弱。

首先,我將刪除所有不包含搜索模式的行( HTMName=在行的開頭),然后我將刪除搜索的模式

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

:v表示在{pattern}(在這種情況下,行的開頭“HTMName =”)不匹配的行上執行命令(在本例中為“:d”)。

:d表示刪除行。

在幫助中查看更多:

PS:如果您的模式不在一行中,您可以嘗試

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM