0

I would like to delete some prefix from all words in document using VSCodeVim plugin. For example:

var someVarOne, someVarTwo, someVarThree;

delete prefix 'some' and get:

var VarOne, VarTwo, VarThree;

Thanks in advance!

Gama11
  • 31,714
  • 9
  • 78
  • 100
i474232898
  • 781
  • 14
  • 25

3 Answers3

2

Try:

%s/some\(Var\w*\)/\1/g
  • \(...\) defines a group
  • \w* one or more word chars
  • \1 replaced with the first group (whatever matched by Var\w*)
Ralf
  • 1,773
  • 8
  • 17
2

Assuming your var are camelCase as you showed and that only the "some" word is known (i.e., "Var" might change) try this regex:

some(([A-Z][a-z]*)+)

and replace with \1

regex demo.

Works on

var someVarOne, someVarTwo, someVarThree, someOtherVar, someVar, someThing;

var some;

producing:

var VarOne, VarTwo, VarThree, OtherVar, Var, Thing;

var some;

Mark
  • 143,421
  • 24
  • 428
  • 436
2

Since the substitution methods have already been mentioned, you could try this simple method:

  1. Visually select the word to be replaced (here it's "some") using the v key.
  2. Place multiple cursors at all places where the word "some" has occurred by Ctrl+Shift+L or Cmd+Shift+L keys.
  3. Delete the visually selected parts using d key which stands for delete
Yedhin
  • 2,931
  • 13
  • 19