I'm trying the following command in visual mode to attempt a global find/replace on a block of text
我正在以可视模式尝试以下命令来尝试对文本块进行全局查找/替换
:'<,'>s/red/green/g
The text looks like this
文字看起来像这样
red red red blue red red red blue
红色红色红色蓝色红色红色红色蓝色
And the result
结果
green red red blue red red red blue
绿色红色红色蓝色红色红色红色蓝色
Instead of what I am expecting with the g switch:
而不是我期望与g开关:
green green green blue green green green blue
绿色绿色绿色蓝色绿色绿色绿色蓝色
Any idea what causes this behaviour? If it is default behaviour how do I make g really really global?
知道导致这种行为的原因吗?如果它是默认行为,我如何让g真正全球化?
Thanks
2 个解决方案
#1
8
You've probably :set gdefault
; this inverts the meaning of the g
substitution flag. You can check where it got set via :verbose set gdefault?
and temporarily turn it off via :set nogdefault
, but you probably want to find the place where it got set and remove it from there.
你可能:设置gdefault;这颠倒了g替换标志的含义。您可以通过以下方式检查设置的位置:verbose set gdefault?并暂时通过:set nogdefault关闭它,但你可能想找到它设置的地方并从那里删除它。
#2
0
I tried this in my vim and get the correct result as:
我在我的vim中尝试了这个并得到了正确的结果:
green green green blue green green green blue
Maybe there is something in your .vimrc changing the default behavior. Would you like to attach it to this thread?
也许你的.vimrc中有一些东西改变了默认行为。你想把它附加到这个帖子吗?
#1
8
You've probably :set gdefault
; this inverts the meaning of the g
substitution flag. You can check where it got set via :verbose set gdefault?
and temporarily turn it off via :set nogdefault
, but you probably want to find the place where it got set and remove it from there.
你可能:设置gdefault;这颠倒了g替换标志的含义。您可以通过以下方式检查设置的位置:verbose set gdefault?并暂时通过:set nogdefault关闭它,但你可能想找到它设置的地方并从那里删除它。
#2
0
I tried this in my vim and get the correct result as:
我在我的vim中尝试了这个并得到了正确的结果:
green green green blue green green green blue
Maybe there is something in your .vimrc changing the default behavior. Would you like to attach it to this thread?
也许你的.vimrc中有一些东西改变了默认行为。你想把它附加到这个帖子吗?