tags:

views:

86

answers:

2

I have this pattern

a,abc_def_eghi
1,234_556
5,567_987_ghi

I want to replace the first _ with a ",". I know %s/old/new/g to replace contents in vim.

Result

a,abc,def_eghi
1,234,556
5,567,987_ghi

Could you suggest some alternatives to go about it

+7  A: 

The "g" is for "global". If you leave it off, the substitution will apply only once on each line.

%s/old/new/

Kevin Beck
+3  A: 

If you only want to replace the first occurrence of a match, do not use the g modifier. That is, use s/old/new/ instead of s/old/new/g. More vim search/replace tips and tricks can be found over at Wikia.

Stephan202