Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

In vim, I know I can search with or without case sensitivity. But if I want to search for a string in either upper or lower case, and replace it with a replacement of the same case, is that possible in a single :s///?

For example, I want to change these lines:




I can do this in three :s commands, or one insensitive :s and go fix the cases manually, but is there a better way? A case-preserving search and replace?

share|improve this question
up vote 3 down vote accepted

There isn't a native feature of :s that does this as far as I know, but if you're willing to install add-ons, you could look at Michael Geddes' keepcase plugin.

share|improve this answer

You can try this plugin.


This plugin can help you to match not just the case sensitive text, also its variants too. Like /good{,ies} will match both good as well as goodies.

Similarly, it can replace with case sensitive as well as variant included.


will replace long with short, Long with Short, LONG with SHORT.

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.