Case preserving substitute in Vim

Can this can be done in Vim?

What I mean is: searching for 'BadJob' and replacing with 'GoodJob' would do the following replacements

'badjob' -> 'goodjob'  
'BadJob' -> 'GoodJob'  
'badJob' -> 'goodJob'  
'BADJOB' -> 'GOODJOB'

Solution 1:

Use abolish.vim:

:%S/badjob/goodjob/g

Solution 2:

I don't know if this is the kind of solution you're looking for... but i've used this: keepcase.vim

There's no support otherwise in vim...

Solution 3:

sure u can

:s/\cbad/\= strpart(submatch(0), 0 ,1) == toupper(strpart(submatch(0), 0, 1)) ? "GOOD" : "good"/

ps. i'm guessing keepcase.vim encapsulates some similar logic :)