I have some lines like below:
aaa
bbb
ccc
ddd
I want them to be changed like this:
aaa=$aaa
bbb=$bbb
ccc=$ccc
ddd=$ddd
so I use the following command to do it in vim, but I got an error
:s/\(\^*\)/\1=\$\1/
and I realized the \1 here could not be used twice, then how should I do this?
The back reference
\1can be used as many times as you wish, but you have another problem. Your regex should look like that:Explanation: the
%tells vim to replace on all lines;^as a mark for the beginning of line should be the first character in your regex and should not be escaped. The.*means “any character any number of times”. However, the original expression\(\^*\)will look for any number of repeats of the literal character^(including none).