Java 注释/取消注释 NetBeans 快捷方式中的代码块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2010360/
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
Comment/uncomment a block of code in NetBeans shortcut
提问by mrblah
Is there a shortcut in NetBeans to highlight a block of code and comment/uncomment it?
NetBeans 中是否有突出显示代码块和注释/取消注释的快捷方式?
采纳答案by lofte
The list of keyboard shortcuts can be found in the NetBeans Wiki.
可以在NetBeans Wiki 中找到键盘快捷键列表。
Turn On/Off Search Result highlights
打开/关闭搜索结果突出显示
Alt+ Shift+ H
Alt+ Shift+H
Add/remove comment. Should work for all languages
添加/删除评论。应该适用于所有语言
Ctrl+ /or in mac?+ /
Ctrl+/或在 Mac?+/
回答by Girish
Try this combination in the Netbeans Editor: ctrl+ shift+ c
在 Netbeans 编辑器中试试这个组合:ctrl+ shift+c
回答by Willem Van Onsem
An IDE independent trick (that works for all languages in the C/Java/C++/C# family) I found to comment/uncomment blocks of code fast is the following:
我发现可以快速注释/取消注释代码块的一个独立于 IDE 的技巧(适用于 C/Java/C++/C# 系列中的所有语言)如下:
int a = 5;
int b = 2;
//*
if(a < b) {
int t = a;
a = b;
b = t;
}
//*/
System.out.println("a: "+a);
Say you want to comment and uncomment the if
block frequently. You can use the //*
and //*/
markers. You comment the block by removing one /
in the //*
part. Thus:
假设您想经常注释和取消注释if
块。您可以使用//*
和//*/
标记。您可以通过删除一个注释块/
中的//*
一部分。因此:
int a = 5;
int b = 2;
/*
if(a < b) {
int t = a;
a = b;
b = t;
}
//*/
System.out.println("a: "+a);
Why this works
为什么这有效
In case the first line reads //*
, it is interpreted as // *
, thus you comment the *
and don't comment the remainder of the block. The //*/
is ignored as well since it is interpreted as // */
.
如果第一行读取//*
,则将其解释为// *
,因此您可以注释*
并且不注释块的其余部分。该//*/
被忽略,以及因为它被解释为// */
。
In case the first line reads /*
, it is interpreted as the start of a comment block. Java searches for the corresponding end which is // */
(the //
is ignored).
如果第一行显示为/*
,则将其解释为注释块的开始。Java 搜索相应的结尾// */
(//
被忽略)。
回答by Xiaogang
In mac, it is more stable to use command+shift+c. Sometimes, command+/ could be usable but not so stable.
在mac中,使用command+shift+c更稳定。有时, command+/ 可以使用但不是那么稳定。
回答by RikiRiocma
Also, to have a whole block commented, can be useful the rectangular selection trick as a single "null column" rectangle where we can add any comment character we like (eg. an hash or a slash):
此外,要对整个块进行注释,将矩形选择技巧用作单个“空列”矩形可能很有用,我们可以在其中添加我们喜欢的任何注释字符(例如哈希或斜杠):
The shortcut in Mac is Ctrl+Shift+Ras explained in this thread.
在Mac上的快捷键是Ctrl+ Shift+R中的说明这个线程。
To return to the normal selection just repeat the same shortcut.
要返回正常选择,只需重复相同的快捷方式。