0

How using vim serach and replace change

title: <Translation {...messages.title} />,
title: <Translation {...messages.header} />,
title: <Translation {...messages.message} />,

into

title: <Translation id="key.subkey.title" />,
title: <Translation id="key.subkey.header"  />,
title: <Translation id="key.subkey.message"  />,

I've thought about something like: %s/{...messages\.[a-zA-Z ]*\}/id="\1"/g But I don't know how to make [a-zA-Z ]*\ a reference to be used to paste in the new form.

2

But I don't know how to make [a-zA-Z]* a reference to be used to paste in the new form

Just put it inside \( and \), that way you can refer to it in the replacement as \1 (assuming that's the first group inside parentheses.)

%s/{\.\.\.messages\.\([a-zA-Z]*\)}/id="key.subkey.\1"/

See also :help s/\1.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.