sometimes my global subtistusions doesn't substitute all matches in a line. It is confirmed by the fact that I can see it when I do substitutions with confirmation, a match is found in a line with multiple possible matches, but then it go to another line.I use the g or gc parameters operating on the entire file with %.On this file:hello hellohellohello hello hellohelloIf I do %s/hello/goodbye/g I getgoodbye hellogoodbyegoodbye hello hellogoodbyeAll I have in my .vimrc about search/replace isset hlsearchset ignorecaseset incsearch
Vim global substitution doesn't substite all matches in a line
substitute
Maybe you, or a plugin, had enabled the option 'gdefault'. This option adds the flag g automatically whenever you perform a substitution.So, when you manually add the flag g while 'gdefault' is enabled, it's as if you had 2 g flags which has the same effect as none. Therefore, Vim only substitutes the first occurrence of the pattern on every line.By default, this option is disabled, but to make sure it is, you could add at the end of your vimrc: set nogdefault.Alternatively, if you suspect a plugin might have enabled the option, you could track it down with: verb set gd? Or you could get used to the option which means that when you want to substitute all the occurrences of a pattern, you don't add the g flag (because gdefault already did it), and when you want to only substitute the 1st occurrence of the pattern on a line, you add the g flag (because 2 g flags is the same as none).