问题
I used this way to get code folding in Netbeans:
// <editor-fold defaultstate="collapsed" desc=" description">
....
// </editor-fold>
and Visual Studio:
#region description
...
#endregion
but I can't find the same usage in eclipse. How can i use code folding in Eclispe?
回答1:
Eclipse supports code folding.
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.
回答2:
The <editor-fold
and #region
can 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.
Eclipse does not has such functionality. I am using Eclipse Neon and still missing this.
回答3:
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
回答4:
I created a fork and an update site for the old coffee bytes code folding plugin that works with Eclipse Neon: https://github.com/stefaneidelloth/EclipseFolding/raw/master/com.cb.platsupp.site
回答5:
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 #region
and #endregion
directives, or Netbeans with its //<editor-fold defaulstate="collapsed" desc="My custom code folding block"
and //</editor-fold>
.
(IntelliJ supports this as well, with both aforementioned methods working, depending on how the IDE is configured.)
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.
Create a header file in a central location, which contains macros, etc (optional). In that header, simply define a FOLD macro, as below:
#define FOLD //
Each file that #includes your central header file will also have a reference to the macro above.
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
I hope this is of some use!
来源:https://stackoverflow.com/questions/13505413/code-folding-in-eclipse