Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim visual block search/replace only replacing first occurrence on a line

Tags:

regex

replace

vim

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:

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?

Thanks

like image 241
darryn.ten Avatar asked Dec 03 '12 07:12

darryn.ten


1 Answers

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.

like image 93
Ingo Karkat Avatar answered Oct 19 '22 07:10

Ingo Karkat