Is there an easy way to delete all comments from an open file in VSCode? Preferably both line and block comments.
Most interested in Java, but also Python and R.
解决方案
Easy way:
Open extensions (ctrl-shift-x)
type in remove comments in the search box.
Install the top pick and read instructions.
Hard way (I guess)
search replace(ctrl-h)
toggle regex on (alt-r).
A simple //.* will match all single line comments (and more ;D). #.* could be used to match python comments. And /\*[\s\S\n]*\*/ matches block comments. And you can combine them as well: //.*|/\*[\s\S\n]*\*/ (| in regex means "or", . means any character, * means "0 or more" and shows how many characters to match, so therefor .* means all characters until the end of the line)
Of course with caveats, such as urls (https://...) has double slashes and will match that first rule, and god knows where there are # in code that will match that python-rule. So some reading/adjusting has to be done!
Once you start fiddling with your regexes it can take a lifetime to get them perfect, so be careful. I'd probably go the easy route if you haven't touched regexes before! But knowing some simple regex by heart will do you good, since it's usable almost everywhere.