1

I have to change strings:

  • fetchrandomData to fetchReportingData
  • FETCH_RANDOM_DATA to FETCH_REPORTING_DATA

I can change ca_z and CA_Z to ca_t and CA_T respectively with command:

%s/\v([Cc])([Az])(_)?([Tt])/\1\2\3\4/gci.

For a string with 3 or more characters this method seems unfeasible, let alone for string FETCH_RANDOM_DATA of length 17 characters.

What is more a feasible way to do something like this in vim?

  • What does this have to do with sed, exactly? (Although I would take a look at tpope’s Abolish plugin, it handles this nicely.) – D. Ben Knoble Dec 16 '18 at 19:34
  • Agreed @Rich , the second is a change of words and has nothing to with case. The first doesn’t change the word but does modify the case. – D. Ben Knoble Dec 16 '18 at 19:55
  • As well as remembering the case you also want to remember the presence or absence of underscores? – Rich Dec 16 '18 at 20:10
  • Is the r in random in your first example still lowercase deliberately? – Rich Dec 16 '18 at 20:13
  • Yes. Using command s/\vfetch(_)?random(\1)?/fetch\1Reporting\1/gci, I end up with fetch_Reporting_DATA for FETCH_RANDOM_DATA. The first example fetchrandomData is replaced successfully with fetchReportingData – HarshvardhanSharma Dec 16 '18 at 20:22

Your Answer

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

Browse other questions tagged or ask your own question.