在 Vim 中的多行中替换不同长度的文本

Replacing varying length text over multiple lines in Vim

假设我在 Vim 中打开了一个文本文件:

Hello Tom. How's your mom?
HellO Sam. Pass me the Jam.
Hell0 Jim. Do you know Vim?

我可以使用视觉块技巧将这三个名称替换为 "friend"。但是如果三个名字的长度不同呢?

Hello Kat. You're not fat...
HellO Mike. Where's Pike?
Hell0 James. Hunger games?

是否可以用 "friend" 替换 Cat、Mike 和 James?如果他们被相同的字符包围怎么办,例如html 个标签?

Hello <Steph>. You seen Jeff?
HellO <Mat>. Here's your hat.
Hell0 <Jenny>. Got a penny?

如果这些是 doable/easy,有没有办法从文件中的相似段落中提取单个段落?谢谢

But what if the three names were of different length?

:%s/\m\w\+\ze\./friend/

这将替换每行第一个句点之前的单词。

How about if they were surrounded by the same characters, e.g. html tags?

:%s/\m\w\+\ze>\./friend/

这将替换每行第一对 >. 之前的单词。

还有:

:%s/\m\<\%(Steph\|Mat\|Jenny\)\>/friend/

这会替换每行中第一次出现的 StephMatJenny

is there a way to do it for a single paragraph out of similar paragraphs in a file?

根据 "paragraph" 的含义,您可以使用 :global。或不。 :)

:%norm WcWFriend

:  ...... command mode
%  ...... whole file
norm .... normal mode
W ....... big word (jump to)
cW ...... change word (change it)

Obs:大词包括“-”分隔和 html 标签