Change snake case to camel case using VIM

As I’m working on refactoring some legacy code, I’ve encountered the challenge of changing the variable naming convention. The current convention is not standardized, and I’ve noticed that snake case (e.g., first_name) is commonly used. One additional constraint is to only change part of a file.

Following will looks for any places with an underscore followed by a lower case letter and replaces that with an upper case letter.

1
    :1,$s/_\([a-z]\)/\u\1/g

If you want to change case on selected lines you can use following.

1
    :3,6s/_\([a-z]\)/\u\1/g
comments powered by Disqus