I often run into a situation where I have a file with a lot of mixed case. For example,

CamelCase and camelCase

I'm looking for a Vim regular expression replacement to produce,

AnotherCase and anotherCase

Right now I do this in two steps after visually selecting the lines,


Is this possible in one replacement step, or should I look into other options like a function in .vimrc?

2 Answers 2


I would suggest using :Subvert via Tim Pope's Abolish.vim


Vimcasts episode: Supercharged substitution with :Subvert

  • This plugin made that so easy. I didn't look under the hood, but thought I'd try :%S/CamelCase/AnotherCase/g, however it only replaces CamelCase and left camelCase as is. No big deal, just something to remember.
    – wsams
    Commented Mar 4, 2016 at 23:15
  • It's likely using smartcase or something to that effect so that any upper case characters are required to be upper case but lower case can be capitalized as necessary. Commented Mar 5, 2016 at 0:19

You also have the venerable keepcase.



you'll obtain:

 totoTitiTata -> titiTutu
 TotoTitiTata -> TitiTutu
 tototititata -> tititutu
 tototitiTata -> titiTutu
 TototitiTata -> TitiTutu 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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