vim在行中单独更改一个事件

时间:2015-03-22 18:43:40

标签: vim

我有这样的文字

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

我想替换“孩子”这个词。有选择地使用vim 所以我用了

  

%S /子/ PID / C

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

这是预期的行为吗?

如果是这样,如何忽略行中的第一次出现,但使用上面的搜索命令替换同一行中的第二个?

1 个答案:

答案 0 :(得分:3)

在第二个g之后添加/('全球')修饰符(以及c(代表'确认'))::%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.