我有一个大文件,我需要在特定模式后编辑一定数量的字符。这是我的文件的一部分的示例:
@IB4UYMV03HCKRV
100 100 100 100 100 100 100 100 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 39 39 39 40 40 40 40
@IB4UYMV03GZDSU
100 100 100 100 100 100 100 100 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 39 39 39 40 40 40 40 40 40 40 40 40 40 40 39 39 39 40 40 40 40 40 40 40 40 40 "
Run Code Online (Sandbox Code Playgroud)
在100 100 100 100 100 100 100 100我想删除接下来的 12 个4036 个带空格的字符之后。我尝试使用查找和替换,但字符并不总是40,它们可以是任何两个数字。
有没有办法删除模式后的 36 个字符?
如果将光标放在412 40s字符串中的第一个上,则可以36x在正常模式下进行,这将删除单个字符 36 次。
或者,如果您有常规模式,则可以使用以下替换:
:%s/^\v(100 ){8}\zs(\d\d ){12}/
Run Code Online (Sandbox Code Playgroud)
分解:
Ex Command:
% All lines
s Substitute
Pattern:
^ Anchor to start of line
\v Very magic mode, to avoid excessive slashes
(100 ){8} 8 instances of the string "100 "
\zs Start selection
(\d\d ){12} 12 instances of the string "\d\d " (i.e., \d is any digit)
Replacement:
Nothing (i.e., remove it)
Run Code Online (Sandbox Code Playgroud)
“选择”是最终被替换的部分。请注意,没有匹配\ze(结束选择),因为我们不关心模式如何结束。