2

What is the most convenient way to do search and replace for same words in multiple formats. I often find myself doing tons of regular expressions as follows.

:%s/scubaDiver/deviceDriver/g
:%s/ScubaDiver/DeviceDriver/g
:%s/scuba_diver/device_driver/g
:%s/Scuba_diver/Device_driver/g
:%s/scuba-diver/device-driver/g
:%s/Scuba-diver/Device-driver/g
:%s/SCUBA-DIVER/DEVICE-DRIVER/g
1

The vim-abolish plug-in has a :Subvert command that does something very close to what you want.

This command covers 5 of the 7 cases you mentioned:

%Subvert/scuba{_,-,}Diver/device{_,-,}Driver

It doesn't seem to cover the cases with a delimiter and mixed case, in specific Scuba_diver and Scuba-diver, presumably because it will try to define the most common capitalizations you'd encounter in coding conventions (camel case, snake case, etc.) Maybe there's a way to get it to cover all these exact cases, but it wasn't immediately apparent to me how to do so (digging further might uncover it.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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