I have a file with three lines.
HelloStackOverflow
ThisIsMyFirstPost
OnThisWebsite
I want it to look like this.
HELLO_STACK_OVERFLOW
THIS_IS_MY_FIRST_POST
ON_THIS_WEBSITE
Is there a way to do this using Vim's substitution? I currently have this.
:%s/^\([A-Z][a-z]*\)*\([A-Z][a-z]*\)$/\U\1_\2/g
The first group captures all words up to the last in each line, and the second group captures the last. Can I "expand" the backreference to the multiple matches of the first group, so _ can be put after each one? Currently, it produces this.
STACK_OVERFLOW
FIRST_POST
THIS_WEBSITE
(\1 gives the last wildcard match)