Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 6 down vote accepted

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


Vimcasts episode: Supercharged substitution with :Subvert

share|improve this answer
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 Mar 4 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. – dash-tom-bang Mar 5 at 0:19

You also have the venerable keepcase.



you'll obtain:

 totoTitiTata -> titiTutu
 TotoTitiTata -> TitiTutu
 tototititata -> tititutu
 tototitiTata -> titiTutu
 TototitiTata -> TitiTutu 
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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