First, we must know the pattern of the modifiers that you want to remove. It could be something as simple as
boolean\|string\|IList if these are the only keywords, or you could write a more complex expression. For intsance, to match any keyword that is not in a given list, one could use
\(\(class\|interface\)\>\)\@!\(\w\+\). The first part specifies the list of words that should not be matched. It uses
\@! to say that the expression should match as long as the preceding part does not match. The final part matches any word. Combined, this would match any word that is not
There are several ways of solving the initial problem. Here are two regular expression substitutions:
Note that we don't need the final
/, since we don't need to provide any flags here. The first expression uses a sub-expression with the
\(...\) syntax and substitutes the matching text with the content of the matched sub-expression. The second expression uses
\ze to set the end of the match. This means that the following part must match, but it won't be counted as part of the matched text. Thus only the
public part is matched and removed by the substitute command.
You could also use a global command, e.g.:
:g/public \(boolean\|string\|IList\)/ norm! 0dw
This will perform the normal mode "command"
0dw (move to first column then delete the following word) on all lines that match the regular expression. I think the current task is best solved by a substitute command, but the global command can be useful in similar, but more complex, tasks.