Accepted answer

there's no such standard equivalent. some ides - intellij, for instance, or eclipse - can fold depending on the code types involved (constructors, imports etc.), but there's nothing quite like #region.


there is some option to achieve the same, follow the below points.

1) open macro explorer:

2) create new macro:

3) name it "outlineregions" (or whatever you want)

4) right click on the "outlineregions" (showing on macro explorer) select the "edit" option and paste the following vb code into it:

    imports system
imports envdte
imports envdte80
imports envdte90
imports envdte90a
imports envdte100
imports system.diagnostics
imports system.collections

public module outlineregions

    sub outlineregions()
        dim selection as envdte.textselection = dte.activedocument.selection

        const region_start as string = "//#region"
        const region_end as string = "//#endregion"

        dim text as string = selection.text

        dim startindex as integer
        dim endindex as integer
        dim lastindex as integer = 0
        dim startregions as stack = new stack()

            startindex = text.indexof(region_start, lastindex)
            endindex = text.indexof(region_end, lastindex)

            if startindex = -1 andalso endindex = -1 then
                exit do
            end if

            if startindex <> -1 andalso startindex < endindex then
                lastindex = startindex + 1
                ' outline region ...
                selection.movetolineandoffset(calclinenumber(text, cint(startregions.pop())), 1)
                selection.movetolineandoffset(calclinenumber(text, endindex) + 1, 1, true)

                lastindex = endindex + 1
            end if

    end sub

    private function calclinenumber(byval text as string, byval index as integer)
        dim linenumber as integer = 1
        dim i as integer = 0

        while i < index
            if text.chars(i) = vbcr then
                linenumber += 1
                i += 1
            end if

            i += 1
        end while

        return linenumber
    end function
end module

5) save the macro and close the editor.

6) now let's assign shortcut to the macro. go to tools->options->environment->keyboard and search for your macro in "show commands containing" textbox (type: macro into the text box, it will suggest the macros name, choose yours one.)

7) now in textbox under the "press shortcut keys" you can enter the desired shortcut. i use ctrl+m+n.



8) press the saved shortcut key

see below result:

enter image description here


just intall and enable coffee-bytes plugin (eclipse)


in eclipse you can collapse the brackets wrapping variable region block. the closest is to do something like this:

public class counter_class 

    { // region

        int variable = 0;



in visual studio code, try this:

//region variables
// code you need


actually johann, the # indicates that it's a preprocessor directive, which basically means it tells the ide what to do.

in the case of using #region and #endregion in your code, it makes no difference in the final code whether it's there or not. can you really call it a language element if using it changes nothing?

apart from that, java doesn't have preprocessor directives, which means the option of code folding is defined on a per-ide basis, in netbeans for example with a //< code-fold> statement


on mac and android studio follow this sequence:

  1. highlight the source code to fold
  2. press alt+command+t
  3. select <editor-fold>

also you can select other options:

enter image description here


meet custom folding regions ⌥⌘t



i usually need this for commented code so i use curly brackets at start and end of that.

// code
// code
// code
// code

it could be used for code snippets but can create problems in some code because it changes the scope of variable.



i use vscode for java and it works pretty much the same as visual studio except you use comments:

//#region name



enter image description here



// code


really only gets you any benefit in the ide. with java, there's no set standard in ide, so there's really no standard parallel to #region.


if anyone is interested, in eclipse you can collapse all your methods etc in one go, just right click when you'd normally insert a break point, click 'folding' > 'collapse all'. it know it's not an answer to the question, but just providing an alternative to quick code folding.


here is an example:

//region regionname

100% works in android studio


the best way

//region description_region
int x = 22;
// comments
string s = "somestring";

tip: put ";" at the end of the "endregion"


i were coming from c# to java and had the same problem and the best and exact alternative for region is something like below (working in android studio, dont know about intellij):

 //region [description]
 int a;
 int b;
 int c;

the shortcut is like below:

1- select the code

2- press ctrl + alt + t

3- press c and write your description


contrary to what most are posting, this is not an ide thing. it is a language thing. the #region is a c# statement.


androidstudio region
create region

first, find (and define short cut if need) for surround with menu enter image description here

then, select the code, press ctrl+alt+semicolon -> choose region..endregion...
enter image description here

go to region

first, find custom folding short cut
enter image description here second, from anywhere in your code, press ctrl+alt+period('>' on keyboard) enter image description here


the fastest way in android studio (or intellij idea)

  1. highlight the code you want to surround it
  2. press ctrl + alt + t
  3. press c ==> then enter the description
  4. enjoy


this is more of an ide feature than a language feature. netbeans allows you to define your own folding definitions using the following definition:

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

as noted in the article, this may be supported by other editors too, but there are no guarantees.


custom code folding feature can be added to eclipse using coffeescript code folding plugin.

this is tested to work with eclipse luna and juno. here are the steps

  1. download the plugin from here

  2. extract the contents of archive

  3. copy paste the contents of plugin and features folder to the same named folder inside eclipse installation directory
  4. restart the eclipse
  5. navigate window >preferences >java >editor >folding >select folding to use: coffee bytes java >general tab >tick checkboxes in front of user defined fold

    enter image description here

  6. create new region as shown:

    enter image description here

  7. restart the eclipse.

  8. try out if folding works with comments prefixed with specified starting and ending identifiers

    enter image description here

    enter image description here

you can download archive and find steps at this blog also.


no equivalent in the language... based on ides...

for example in netbeans:

netbeans/creator supports this syntax:

// <editor-fold defaultstate="collapsed" desc="your fold comment">
// </editor-fold>


with android studio, try this:

//region variables
private string _smyvar1;
private string _smyvar2;

careful : no blank line after //region ...

and you will get:


jet brains idea has this feature. you can use hotkey surround with for that (ctrl + alt + t). it's just idea feature.

regions there look like this:

//region description

some code


Related Query

More Query from same tag