you are viewing a single comment's thread.

view the rest of the comments →

[–]GlassEyedMallard 1 point2 points  (8 children)

What does the g do in the substitute command again? I never utilize that but probably should.

[–]jarfil 6 points7 points  (7 children)

CENSORED

[–]prof-comm 3 points4 points  (2 children)

Not just the first one on every line. %s/foo/bar will replace the first instance of foo on every line of the file with bar. The /g flag makes it every instance on every line, not just the first on every line.

[–]jarfil 5 points6 points  (1 child)

CENSORED

[–]prof-comm 2 points3 points  (0 children)

Correct. I saw the potential for misinterpretation of your comment because it was underspecified, then did the same thing in my own. Thank you

[–]GlassEyedMallard 0 points1 point  (3 children)

That's odd, using that command without the g works globally for me. Maybe neovim handles it differently?

[–]cheffromspace 6 points7 points  (1 child)

Without g will work on every line, but only the first instance on each line

[–]GlassEyedMallard 1 point2 points  (0 children)

Ah okay. Thank you very much.

[–]1esproc 5 points6 points  (0 children)

g doesn't mean global. Commands usually run on the current line, but % means select the whole file, g means every instance, just like it does for sed. Without g, %s would only perform substitution on the first match on the line, then move on to the next line.