Skip to content

Bulk Replacement

Johnny M. Salas edited this page May 2, 2022 · 1 revision

Bulk replacement

Given two pieces of text A and B, it searches for all of A variants (in different string cases or custom functions), and replaces the text using B. It transforms and uses B, according to the target transformation. String cases are prioritized over custom Lua functions

Suppose constant, camel and dash cases were registered under the same command Subs. Take into account it is possible to setup multiple commands grouping different methods

shake.register_replace_command('Subs', {
  shake.api.to_dash_case,
  shake.api.to_constant_case,
  shake.api.to_camel_case,
})

Activate the search replace feature via command mode:

:Subs/{string to be replaced}/{replacement string}

Let's say you want to replace the StepOne component name to StudentsOnboarding in the following piece of code:

import StepOne from './components/step-one';

const SampleWizard = () => {
  const [currentStep, setCurrentStep] = useState(1)
  if (currentStep === steps.STEP_ONE)  {
    return <StepOne />
  }
}

Executing :Subs/step one/students onboarding will result into:

import StudentsOnboarding from './components/students-onboarding';

const SampleWizard = () => {
  const [currentStep, setCurrentStep] = useState(1)
  if (currentStep === steps.STUDENTS_ONBOARDING)  {
    return <StudentsOnboarding />
  }
}

note: The actual component will not be renamed yet because LSP renaming is not enabled for bulk replacement

Built-in string transforms

Clone this wiki locally