gpt4 book ai didi

vim - 如何在vim中删除字符串后的一定数量的字符?

转载 作者:行者123 更新时间:2023-12-04 02:10:12 27 4
gpt4 key购买 nike

我有一个大文件,我需要在特定模式后编辑一定数量的字符。这是我的文件的一部分的示例:

@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 "

100 100 100 100 100 100 100 100我想删除接下来的十二个 40这是 36 个带空格的字符。我尝试使用查找和替换,但字符并不总是 40 ,它们可以是任意两位数字。

有没有办法在模式后删除 36 个字符?

最佳答案

如果将光标放在第一个 4 上在你的 12 串中 40 s,你可以做36x在普通模式下将删除单个字符 36 次。

或者,如果您有常规模式,则可以使用以下替换:

:%s/^\v(100 ){8}\zs(\d\d ){12}/

分解:
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)

“选择”是最终被替换的部分。请注意,没有匹配的 \ze (结束选择),因为我们不关心模式如何结束。

关于vim - 如何在vim中删除字符串后的一定数量的字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18784698/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com