https://stackoverflow.com/questions/782511/case-preserving-substitute-in-vim
Nobody in this thread understands vim. They think vim is about fancy things like submatch, and plugins. To solve a simple problem, they write terrible code which is only usable in vim. Can’t even re-use it in a script.
What nonsense.
vim, like unix, is not about fancy and complicated commands
vim is fundamentally a text editor within the unix operating system. Like other unix programs, its main value is playing really nicely with other programs.
In particular, you can pipe lines to any unix executable and write the result back into vim. An executable written in any language. Not stupid vim (only) script or emacs (only) lisp. But a language you already know. To write a generally reusable executable.
So, with this in mind, here’s a simple solution to the problem of a special find and replace.
I’ll punt the general case presented in stack overflow because I only care about something that does both:
foo → bar
Foo → Bar
…