views:

318

answers:

2

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'
+8  A: 

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...

LB
+4  A: 

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 :)

fc
Yes it does since 2007: :%SubstituteCase/\cbadjob/GoodJob/g ^^
Luc Hermitte
Meaning since gVim 7.2? I tried it in gVim 7.1 (12-May-2007) and it din't work :(
fc
No, I've added the :SubstituteCase command to the plugin in 2007. That's all. The plugin is available on vim.org, and it is not shipped with vim as usual with with most plugins.
Luc Hermitte