vim 单独更改一行中的一个

vim change one occurrence alone in the line

我收到过这样的短信

pid_t child;
long orig_eax;
child = fork();
if(child == 0) {
    printf("the child is happy %d", child);
    printf("the child");

我想用 vim 有选择地替换单词 'child' 所以我用了

%s/child/pid/c

所以它在替换每场比赛之前询问我 但是当第 5 行出现两次 'child' 时,我想单独替换第二个,所以当它提示更改第一次出现时我给出了 'n',然后询问下一次出现在同一行中,它跳过整行并转到下一行。

这是预期的行为吗?

如果是这样,如何使用上述搜索命令忽略该行中的第一个匹配项,而替换同一行中的第二个匹配项?

在第二个 / 之后添加 g ('global') 修饰符(连同 c(代表 'confirm'))::%s/child/pid/cg

有关标志的更多信息,请查看 :help s_flags

例如,对于 g 标志:

[g]     Replace all occurrences in the line.  Without this argument,
        replacement occurs only for the first occurrence in each line.  If
        the 'edcompatible' option is on, Vim remembers this flag and toggles
        it each time you use it, but resets it when you give a new search
        pattern.  If the 'gdefault' option is on, this flag is on by default
        and the [g] argument switches it off.