Q:

vim repeat a pattern in a replace command

I have the following text:
Lang1
Lang2
Lang3

Now I want to replace all the text in each line with a pattern like:
{ DisplayName: DispName(Lang1), Value: Lang1 },
{ DisplayName: DispName(Lang1), Value: Lang2 },
{ DisplayName: DispName(Lang1), Value: Lang3 },

Now how do I achieve this with the vim command substitution, I can get: :%s/*$/\{\ DisplayName\:\ DispName\(Lang1\)\,\ Value\:\ Lang1\}\,/ to replace each line with Lang1 and then replace the individual 1s with 2, 3, 4, etc. But I do not want to do that. I want a single substitute command to select the pattern and repeat it. How to achieve this ?

A:

You can use:
:%s/.*/{ DisplayName: DispName(&), Value: &},/

Here & is back-reference of complete matched string using .*. This will replace given content with this content:
{ DisplayName: DispName(Lang1), Value: Lang1},
{ DisplayName: DispName(Lang2), Value: Lang2},
{ DisplayName: DispName(Lang3), Value: Lang3},

If you want to be more specific then you may use this regex instead of .*:
^Lang[0-9]*$

