可能的重复:
Vim :s 替换一行中出现的第一个 N < g 次
在六,我该如何搜索和替换单词的第n一个出现的词语,说“你好”,而接下来m发生与bonjour,和所有其余的namaste?
你能手动找到第n个“hello”吗?如果是这样,那么我将按如下方式找到第 n 个 hello:
:1 (goes to the first line of your file)
n/hello (find the nth hello, where n is the number)
Run Code Online (Sandbox Code Playgroud)
然后将所有的 hello 替换如下:
:1,.s/hello/bonjour/g
(move to the next line)
:.,$s/hello/namaste/g
Run Code Online (Sandbox Code Playgroud)