VSCode:删除文件中的所有注释 [英] VSCode: delete all comments in a file
问题描述
是否有一种简便的方法可以从VSCode中的打开文件中删除所有注释?
Is there an easy way to delete all comments from an open file in VSCode? Preferably both line and block comments.
对Java最感兴趣,但对Python和R也最感兴趣。
Most interested in Java, but also Python and R.
推荐答案
简便方法:
- 打开扩展名(ctrl-shift-x)
- 在
删除评论
中键入。 - 安装首选并阅读说明。
- Open extensions (ctrl-shift-x)
- type in
remove comments
in the search box. - Install the top pick and read instructions.
- 搜索replace(ctrl-h)
- 在(alt-r)上切换正则表达式。
- 学习一些正则表达式! https://docs.rs/regex/0.2.5/regex/#syntax
- search replace(ctrl-h)
- toggle regex on (alt-r).
- Learn some regular expressions! https://docs.rs/regex/0.2.5/regex/#syntax
在搜索框中
Easy way:
简单的 //.*
将匹配所有单行注释(以及更多; D)。 #。*
可用于匹配python注释。并且 / \ * [\s\S\n] * \ * /
匹配块注释。您也可以将它们组合: //.* | / \ * [\s\S\n] * \ * /
(<$ c regex中的$ c> | 表示或,。
表示任何字符, *
表示 0或更多并显示要匹配的字符数,因此。*
表示直到行尾的所有字符)
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)
当然有警告,例如url( https:// ...
)具有双斜杠,并且将匹配第一个规则,上帝知道哪里代码中有#
个匹配该python-rule的代码。因此,必须进行一些阅读/调整!
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.
这篇关于VSCode:删除文件中的所有注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!