如何在 Eclipse 中注释块?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2001586/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to comment a block in Eclipse?
提问by snakile
Does Eclipse have a hot key to comment a block? and to uncomment a block?
Eclipse 有评论块的热键吗?并取消注释块?
回答by Jon Skeet
Ctrl-/to toggle "//" comments and Ctrl-Shift-/to toggle "/* */" comments. At least for Java, anyway - other tooling may have different shortcuts.
Ctrl-/切换“//”注释和Ctrl- Shift-/切换“/* */”注释。至少对于 Java,无论如何 - 其他工具可能有不同的快捷方式。
Ctrl-\will removea block of either comment, but won't addcomments.
Ctrl-\将删除任一评论块,但不会添加评论。
Note: As for Eclipse CDT 4.4.2, Ctrl-Shift-/will not uncomment a "/* */" block comment. Use Ctrl-Shift-\in that case.
注意:对于 Eclipse CDT 4.4.2,Ctrl- Shift-/不会取消注释“/* */”块注释。在这种情况下使用Ctrl- Shift- \。
EDIT: It's Ctrlon a PC, but on a Mac the shortcuts may all be Cmdinstead. I don't have a Mac myself, so can't easily check.
编辑:它Ctrl在 PC 上,但在 Mac 上,快捷方式可能全部Cmd代替。我自己没有 Mac,因此无法轻松检查。
回答by Ikke
There are two possibilities:
有两种可能:
Every line prepended with //
每一行都以 // 开头
ctrl+ /to comment
ctrl+ \to uncomment
ctrl+/评论
ctrl+\取消评论
Note: on recent eclipse cdt, ctrl+ /is used to toggle comments (and ctrl+ \has no more effect)
注意:在最近的 eclipse cdt 中,ctrl+/用于切换注释(并且ctrl+\没有更多作用)
Complete block surrounded with block comments /*
用块注释包围的完整块 /*
ctrl+ shift+ /to comment
ctrl+ shift+ \to remove
ctrl+ shift+/评论
ctrl+ shift+\删除
回答by Paresh3489227
For Eclipse Editor
对于 Eclipse 编辑器
For Single Line(Toggle Effect)
对于单行(切换效果)
Comment : Ctrl+Shift+c
评论 : Ctrl+ Shift+c
Uncomment: Ctrl+Shift+c
取消注释:Ctrl+ Shift+c
For Multiple Lines(Toggle Effect) (Select the lines you want to comment)
对于多行(切换效果)(选择要评论的行)
comment : Ctrl+Shift+c
注释:Ctrl+ Shift+c
Uncomment: Ctrl+Shift+c
取消注释:Ctrl+ Shift+c
It is for all html , css , jsp , java. It gives toggle effect.
它适用于所有html 、 css 、 jsp 、 java。它提供切换效果。
回答by t3b4n
I came here looking for an answer and ended up finding it myself, thanks to the previous responses.
多亏了之前的回复,我来到这里寻找答案并最终自己找到了答案。
In my particular case, while editing PHP code on Eclipse Juno, I have found that the previous commands won't work for me. Instead of them, I should press Ctrl+ 7(on the superior number key) to obtain the double bar comment ("//"). There's no way I can comment them with the previous mentioned key combinations.
在我的特殊情况下,在 Eclipse Juno 上编辑 PHP 代码时,我发现以前的命令对我不起作用。而不是它们,我应该按Ctrl+ 7(在高级数字键上)来获取双条注释(“//”)。我无法用前面提到的组合键来评论它们。
回答by URL87
I have Eclipse IDE for Java Developers Version: Juno Service Release 2
and it is -
我有Eclipse IDE for Java Developers Version: Juno Service Release 2
,而且是——
Every line prepended with //
每一行都以 // 开头
ctrl+ /for both comment and uncomment .
ctrl+/用于评论和取消评论。
回答by jechterhoff
As other answers pointed out, the following shortcuts are defined by default (I'm referring to editing java source - shortcut bindings can be found in eclipse Window>Preferences, under 'General'/'Keys', search for 'comment'):
正如其他答案所指出的,默认情况下定义了以下快捷方式(我指的是编辑 java 源代码 - 快捷方式绑定可以在 eclipse Window>Preferences 中找到,在“General”/“Keys”下,搜索“comment”):
- to add a block comment, the shortcut (binding) is: Ctrl + Shift + /
- to remove a block comment, the shortcut (binding) is: Ctrl + Shift + \
- 添加块注释,快捷方式(绑定)为:Ctrl + Shift + /
- 要删除块注释,快捷方式(绑定)是:Ctrl + Shift + \
Unfortunately, these shortcuts did not work for me (on Eclipse Java EE IDE for Web Developers, version: Juno Service Release 2).
不幸的是,这些快捷方式对我不起作用(在 Eclipse Java EE IDE for Web Developers 上,版本:Juno Service Release 2)。
The reason, I think, is my keyboard layout (QWERTZ keyboard layout used in Germany - see herefor further information), where '/' actually has to be written via 'Shift + 7'.
我认为原因是我的键盘布局(德国使用的 QWERTZ 键盘布局 - 请参阅此处了解更多信息),其中 '/' 实际上必须通过 'Shift + 7' 写入。
I therefore had to change the shortcut bindings for comments (just did it for editing java source) in the eclipse preferences (under 'General'/'Keys') as follows:
因此,我不得不在 eclipse 首选项(在“General”/“Keys”下)中更改注释的快捷方式绑定(只是为了编辑 java 源代码而这样做),如下所示:
- Change the binding of command 'Add Block Comment' (when 'Editing Java Source') from 'Ctrl + Shift + /' to 'Ctrl + Shift + 7'
- Change the binding of command 'Remove Block Comment' (when 'Editing Java Source') from 'Ctrl + Shift + \' to 'Ctrl + Shift + 8'
- Unbind the binding 'Ctrl + /' for command 'Toggle Comment' (when 'Editing Java Source'); instead of assigning a new binding, I simply unbound this shortcut, as there already was one with Ctrl+7 and one with Ctrl+Shift+C (which both work for me)
- 将命令“添加块注释”(当“编辑 Java 源”时)的绑定从“Ctrl + Shift + /”更改为“Ctrl + Shift + 7”
- 将命令“删除块注释”(当“编辑 Java 源”时)的绑定从“Ctrl + Shift + \”更改为“Ctrl + Shift + 8”
- 取消绑定“Ctrl + /”命令“切换注释”(当“编辑 Java 源代码”时);我没有分配新的绑定,而是简单地取消绑定此快捷方式,因为已经有一个使用 Ctrl+7 和一个使用 Ctrl+Shift+C(这两个都对我有用)
回答by Dani
In addition, you can change Eclipse shortcut in Windows -> Preferences -> General -> Keys
此外,您可以在 Windows -> Preferences -> General -> Keys 中更改 Eclipse 快捷方式
回答by Lovekush Vishwakarma
for java code
对于 Java 代码
if you want comments single line then put double forward slash before code of single line manually or by pressing Ctrl+/example: //System.Out.println("HELLO");
如果你想要单行注释,那么在单行代码之前手动或按Ctrl+/示例放置双正斜杠: //System.Out.println("HELLO");
and for multi-line comments, Select code how much you want to comments and then press
对于多行注释,选择代码要注释多少,然后按
Shift+CTRL+/
Shift+ CTRL+/
Now for XML code comments use Select code first and then press Shift+CTRL+/for both single line and multi-line comments
现在对于 XML 代码注释使用 Select code first 然后按Shift+ CTRL+/用于单行和多行注释
回答by Kamran
For single line comment you can use Ctrl+/and for multiple line comment you can use Ctrl+ Shift+/after selecting the lines you want to comment in java editor.
对于单行注释,你可以使用Ctrl+/和多行注释可以使用Ctrl+ Shift+/在Java编辑器中选择你想要的线路后评论。
On Mac/OS X you can use ? + /to comment out single lines or selected blocks.
在 Mac/OS X 上,您可以使用? +/注释掉单行或选定的块。
回答by Isa Souza
Using Eclipe Oxygen command+ Shift+ con macOSx Sierra will add/remove comments out multiple lines of code
使用氧气的Eclipe command+ Shift+ cMacOSX上塞拉利昂将添加/删除注释出多行代码