Vim global replace (line)

The "global" option does not work as expected (it seems that this has changed only recently, but I still can not find the reason for the difference).

Given the line:

ABA

I issue the command:

: s / a // g

I expect the result to be:

b

However, the resulting string:

ba

What did I miss?

+6
source share
2 answers

Most likely you have gdefault installed in .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 do not install this in your configuration, you can see where it is installed by issuing :verbose set gdefault? .

+17
source

If the input and command exactly match the data, I see no reason for this behavior.

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

+2
source

Source: https://habr.com/ru/post/885416/


All Articles