您可以像在 Visual Studio 中一样在 Netbeans 中设置某种自定义代码折叠吗

StackOverflow https://stackoverflow.com/questions/1251803

  •  12-09-2019
  •  | 
  •  

在使用 C# 时,我经常这样做:

#region Properties
  public int Property1{get;set;}
  ...(more properties)
#endregion

这使得 Visual Studio 添加了将代码折叠到该区域内的选项。当然,您可以将区域用于任何事物,它不限于属性或任何事物。

我想知道两件事:

  1. 这只是为了让 Visual Studio 将代码折叠添加到编辑器的某个区域还是会影响编译器?
  2. 我可以在 Netbeans 中做类似的事情吗?
有帮助吗?

解决方案

  1. (至少在Netbeans中)纯粹是程序员的辅助,对编译没有影响
  2. 是的你可以

对折叠参考的一个警告:

请注意,以上示例适用于 java 语言。在其他语言中,可能不支持自定义折叠,或者您可能必须使用不同的字符来标记行注释。

其他提示

  1. 它不影响编译,只是在 编辑 器。您可以了解何时最好使用它们的争论 这 问题.
  2. 在 NetBeans 中,您可以使用 定制折叠, ,取决于语言:

    // <editor-fold defaultstate="collapsed" desc="My Fold">
    Your amazing code
    // </editor-fold>

属性是可选的。没有 defaultstate 指定区域将默认展开(除非您第一次在其中包装代码!)

最新的 Netbeans 8.1 已经内置了此功能,您只需选择行,然后单击“灯泡”图标,然后选择:

enter code hereSurround with // <editor-fold defaultstatus="collapsed" desc="comment">...

这是来源:http://wiki.netbeans.org/SurroundWithCodeFolding

我编写了一个通过鼠标拖动进行折叠的宏。

我的快捷方式: CTRL+SHIFT+Q

折叠宏:

cut-to-clipboard 
"// <editor-fold desc=\"This is my custom folding\" defaultstate=\"collapsed\">"
 paste-from-clipboard 
"// </editor-fold>"

展开宏快捷方式: ctrl+SUBTRACK

enter image description here

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top