Eclipse 中的代码折叠

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13505413/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 21:26:05  来源:igfitidea点击:

Code folding in Eclipse

eclipsecode-folding

提问by PhatHV

I used this way to get code folding in Netbeans:

我使用这种方式在 Netbeans 中获得代码折叠:

// <editor-fold defaultstate="collapsed" desc=" description">
....
// </editor-fold>

and Visual Studio:

和 Visual Studio:

#region description
...
#endregion

but I can't find the same usage in eclipse. How can i use code folding in Eclispe?

但我在 eclipse 中找不到相同的用法。如何在 Eclispe 中使用代码折叠?

采纳答案by Isaac

Eclipse supports code folding.

Eclipse 支持代码折叠。

Go to workbench preferences -> General -> Editors -> Structured Text Editors, and check the "Enable folding" box.

转到工作台首选项 -> 常规 -> 编辑器 -> 结构化文本编辑器,然后选中“启用折叠”框。

Then go to workbench preferences -> Java -> Editor -> Folding, and adjust your folding preferences.

然后转到工作台首选项 -> Java -> 编辑器 -> 折叠,并调整您的折叠首选项。

回答by ViniciusCR

The <editor-foldand #regioncan be used as a block folding wrapping anything you want, including not just a function or a comment but both or even multiples functions, comments, variables, etc.

<editor-fold#region可以作为你想有一个块折叠包装任何东西,包括不只是一个函数或评论,但两者甚至数倍函数,注释,变量等

Eclipse does not has such functionality. I am using Eclipse Neon and still missing this.

Eclipse 没有这样的功能。我正在使用 Eclipse Neon,但仍然缺少这个。

回答by DanChianucci

Windows->Preferences->(C/C++)->Editors->Folding

Windows->Preferences->(C/C++)->Editors->Folding

(C/C++) will change based on the language you are using. Generally each language plugin will have its own folding options

(C/C++) 将根据您使用的语言而改变。通常每个语言插件都有自己的折叠选项

回答by Stefan

I created a fork and an update site for the old coffee bytes code folding pluginthat works with Eclipse Neon: https://github.com/stefaneidelloth/EclipseFolding/raw/master/com.cb.platsupp.site

我为与 Eclipse Neon 一起使用的旧咖啡字节代码折叠插件创建了一个分支和一个更新站点:https: //github.com/stefaneidelloth/EclipseFolding/raw/master/com.cb.platsupp.site

回答by SimonC

Although this is an old question, I'd like to add some input.

虽然这是一个老问题,但我想添加一些输入。

Eclipse doesn't natively support custom code folding blocks, as does Visual Studio with its #regionand #endregiondirectives, or Netbeans with its //<editor-fold defaulstate="collapsed" desc="My custom code folding block"and //</editor-fold>.

Eclipse 本身不支持自定义代码折叠块,Visual Studio 及其#region#endregion指令或 Netbeans 及其//<editor-fold defaulstate="collapsed" desc="My custom code folding block"//</editor-fold>.

(IntelliJ supports this as well, with both aforementioned methods working, depending on how the IDE is configured.)

(IntelliJ 也支持这一点,上述两种方法都可以工作,具体取决于 IDE 的配置方式。)



If you happen to be working in Eclipse with the CDT (as in C/C++), there is a way around. I've tried installing the plugins mentioned, but they either do not exist anymore, or the installation makes the IDE unstable.

如果您碰巧在 Eclipse 中使用 CDT(如在 C/C++ 中),则有一种方法可以解决。我已经尝试安装提到的插件,但它们要么不再存在,要么安装使 IDE 不稳定。

Create a header file in a central location, which contains macros, etc (optional). In that header, simply define a FOLD macro, as below:

在中央位置创建一个头文件,其中包含宏等(可选)。在该头文件中,只需定义一个 FOLD 宏,如下所示:

#define FOLD //

Each file that #includes your central header file will also have a reference to the macro above.

#includes 中央头文件的每个文件也将引用上面的宏。

An example use of this would be:

使用此方法的一个示例是:

#ifdef FOLD Struct MyFileStruct
#pragma pack(1)
typedef struct MyFileStruct {
        WCHAR fileName[FILENAMELEN];  // File name
        WCHAR fileInfos[32];          // File info
        WCHAR fileDate[32];           // File date
        DWORD sizeInBytes;            // File size
} File;
#pragma pack()
#endif


If the way this works is unclear, I suggest looking in to the C Preprocessor

如果这种工作方式不清楚,我建议查看C Preprocessor

I hope this is of some use!

我希望这有点用!