I'm trying to learn how to use regex with vim, and I'm currently trying to do a search and replace. I have something like this:
aaaaaaa&sometext&...
aaaaaaaanothertext
(the as are actually whitespace at the beginning of the line, that I don't know how to print that here)
And I want to replace the first occurence of & with & &, and keep everyting else as is. I'm using \%(...\) for non-capturing patterns, as suggested here, but the a pattern is still captured. I'm using :%s/\%(^a*\)&/& &/gc, and I get:
aaaaaaaa& aaaaaaaa&sometext&...
aaaaaaaaanothertext
I don't get why. I've also tried the replace with groups, as in :%s/\%(^a*\)\(&\)/\1 \1/gc, but then I get:
& &sometext&...
aaaaaaaanothertext
So, it seems the group is indeed being ignored for the group handling (since the first group is on the search pattern is &), but is still captured on the search pattern.
So, long story short, which replace command do I have to use to go from:
aaaaaaa&sometext&...
to:
aaaaaaa& &sometext&...
?