I have a rather hairy vim regular expression that will capitalise words separated with underscores as below
my_text_example -> My_Text_Example
The regular expression is
s/\(\<\|_\)\([a-zA-Z]\)\([a-zA-Z]*\)/\u\1\u\2\L\3/g
I would like to map that to a key sequence (for example gc). I would also like it to work in visual selection mode.
I tried this
nmap gc :s/\(\<\|_\)\([a-zA-Z]\)\([a-zA-Z]*\)/\u\1\u\2\L\3/g<CR>
in my .vimrc, but I get an error that the regular expression is not found. I haven’t tried the imap version, hopefully that will be simple once I get an answer for the nmap case.
This works:
I think it didn’t work because \< is a zero-width pattern but that is just a wild guess.
If someone can explain why it didn’t work that’d be great!