9

I am working with Eclipse tool and I am so curious to know about that how can I create Region in Eclipse like in Visual Studio we can create :

#region abc

// Some Code 

#endregion abc

How to achieve the same thing in Eclipse.

Nicolás Alarcón Rapela
  • 2,714
  • 1
  • 18
  • 29
Utsav
  • 1,593
  • 4
  • 22
  • 46
  • What behaviour do you want to imitate? What does #region do? – Calon Nov 20 '14 at 09:18
  • #region just collapses the data written between # region and #endregion. so it is useful if you want to hide some unused code or used code. – Utsav Nov 20 '14 at 09:26
  • 1
    Possible duplicate of [Code folding in Eclipse](https://stackoverflow.com/questions/13505413/code-folding-in-eclipse) – Romano Jul 19 '19 at 18:29
  • There is no such method in Eclipse and Intelliji IDE as well. I was from Visual Studio I miss this feature. I think this question possible duplicate of.https://stackoverflow.com/questions/2344524/java-equivalent-to-region-in-c-sharp – Gopi P Nov 11 '19 at 09:33

4 Answers4

3

Got to long for a comment ..

There is code folding in Eclipse. You can find it in Window-> Preferences, then search for "folding". But it just wraps methods/functions/comments etc.

There is a plugin that used to work in Eclipse 4.2 named Coffee Bytes, but it is no longer maintained. So usage is at your own risk.

Lots of "buts", I know ;).

Calon
  • 4,174
  • 1
  • 19
  • 30
0

#region is a feature of the C# language. Unless you are writing C# in Eclipse through some plugin (and there is one actually), you can't. If you are writing C# in Eclipse, then just type it. But I don't know if Eclipse will collapse it like Visual Studio does.

Tsahi Asher
  • 1,767
  • 15
  • 28
  • 2
    Note, it's not really a feature of C#, but of the Visual Studio as an IDE. For instance, you can use #region in Java/JavaScript if you're using Visual Studio Code. – msg45f Sep 03 '19 at 19:13
  • 1
    https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives#defining-regions – ryanwebjackson May 15 '23 at 15:28
0

check this out There is no way to do this in eclipse.The eclipse ide does not provide a way to region off areas of code like visual studio does I came from visual studio to eclipse and this is a problem I had.

Community
  • 1
  • 1
koss
  • 3
  • 3
0

Eclipse does not have something like Visual Studio's region. but you can use the below code and enable folding for this purpose.

#if (1) //myregion
C++ code here
#endif //end myregion

You can add a new template like the below in the Prefrences > C/C++ > Templates menu to add it to surround with and code snippet(auto-complete with CTRL+Space)

#if(1) /* region: ${name} */

${line_selection}${cursor}

#endif   /* region end: ${name} */