开发者

Vim global replace (line)

The "global" option does not work as expected (this seems to have changed only recently, but I'm not abl开发者_如何学Goe to track down the reason for the difference yet).

Given the line:

aba

I issue the command:

:s/a//g

I expect the result to be:

b

However, the resulting line is:

ba

What have I missed?


You most likely have gdefault set in your .vimrc.

From :help gdefault:

When on, the ":substitute" flag 'g' is default on.  This means that
all matches in a line are substituted instead of one.  When a 'g' flag
is given to a ":substitute" command, this will toggle the substitution
of all or one match.

If you are not setting this in your config you can see where it is set by issuing :verbose set gdefault?.


If the input and the command are exactly as you give them, I see no reason for this behaviour.

My money is on the second "a" not being what you think it is. For example, it could be the Cyrillic "a", i.e. "а" (U+0430). On my screen the two are indistinguishable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜