I'm having trouble getting this to work. I'm writing a Vim snippet that will take the current file's name and expand it into a class name, e.g.
If the current file name is: some_awesome_class.foo ... the snippet would expand to class SomeAwesomeClass
So far, I have:
substitute(Filename(), '\(^.\|_\a\)', '\u&', 'g')
.. but this only capitalizes the first letter, even though it correctly matches all the underscores. I guess what I'm looking for is a way to use the underscore as part of the search, but not have it be matched in the ampersand, i.e: it looks for _\a but only matches \a.
Any help would be much appreciated!
Here is a suggestion:
s/\v(^|_)(\a)/\u\2/g
You should exclude the beginning of the line and underscore from the match with \zs.
^.\|_\zs\a
This works, over here.
See :help \zs and :help \ze.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With