找到你要的答案

Q:Why vim does not preserve [c] flag when g& used?

Q:为什么Vim不保留[C]旗当G和使用?

Vim's g& is equal to :%s//~/&. According to documentation it

repeat last substitute with last search pattern on all lines with the same flags

We can specify the c flag to confirm each substitution. If we execute a substitution with gIc flags and we exit with a from replace with xxxx (y/n/a/q/l/^E/^Y)?, then the c flag is not included in the repeated substitution with g&.

Why? Is there any option in vim to cease this unexpected behaviour?

Vim的G &;等于:%s / ~ / &;。根据文档

使用相同的标志在所有行上重复最后一次搜索模式

We can specify the c flag to confirm each substitution. If we execute a substitution with gIc flags and we exit with a from replace with xxxx (y/n/a/q/l/^E/^Y)?, then the c flag is not included in the repeated substitution with g&.

为什么?有任何选项,Vim停止这意想不到的行为呢?

answer1: 回答1:

You're right; the behavior contradicts the documentation. The implementation implements the a(ll) answer by clearing the (static, and therefore persistent) do_ask flag. In the source code, this is in ex_cmds.c, function do_sub():

        if (typed == 'a')
        {
            do_ask = FALSE;
            break;
        }

In fact, there's a similar issue with the l(ast) answer: this one clears do_all, and thereby "forgets" a g(lobal) flag on repetition.

This affects both g& as well as the :&& command.

Edit: Bug reported to vim_dev.

你是对的,行为违背了文件。实现一个(LL)答案通过清除(静态的,因此持久性)do_ask旗。在源代码,这是ex_cmds。C、功能do_sub():

        if (typed == 'a')
        {
            do_ask = FALSE;
            break;
        }

事实上,有与我类似的问题(AST)答:这一do_all清除,从而“忘记”G(全球)国旗的重复。

这会影响G & &;以及:& & & &命令。

编辑:bug报告vim_dev。

vim