PyCharm 3.1.0 Web Help

With PyCharm, you can surround a fragment of source code with line comments. So doing, PyCharm supports two styles:

  • VisualStudio style
                 #region Description 
                 Your code goes here... 
                 #endregion 
                  
  • NetBeans style
                 // <editor-fold desc="Description"> 
                 Your code goes here... 
                 // </editor-fold> 
             

The folding markers of a region are stored with the source code and can be shared across the team.

Note

Do not mix up the two styles in one file. PyCharm will recognize the first folding comment encountered, and will assume this as a style chosen for the code.

To surround a custom region with folding markers
  1. Select a fragment of source code.
  2. On the main menu, choose Code | Surround With, or press Ctrl+Alt+TCtrl+Alt+TCtrl+Alt+TCtrl+Alt+TCtrl+Alt+TCtrl+Alt+TCtrl+Alt+TShift+Alt+Z or Ctrl+Alt+TAlt Command TAlt Command TAlt Command Z.
  3. Select the desired folding comments from the list:

    customFolding1

    PyCharm surrounds the code fragment with comments observing the syntax of the current language.

  4. If necessary, change description of the code fragment to be folded:

    customFolding2

    You can now collapse or expand the code.

    When collapsed, the code is concealed behind the description, and you can view it by hovering your mouse pointer over the description:

    customFolding3

2.7+

Once custom regions are defined, PyCharm provides navigation between them.

To navigate between custom regions
  1. Do one of the following:
    • On the main menu, choose Navigate | Custom Region.
    • Press Ctrl+Alt+PeriodCtrl+Alt+PeriodCtrl+Alt+PeriodCtrl+Alt+PeriodCtrl+Alt+PeriodCtrl+Alt+PeriodCtrl+Alt+PeriodCtrl+Alt+PeriodAlt Command PeriodAlt Command PeriodAlt Command Period.
  2. In the dialog box that opens, select the target custom region, and click OK:

    navigateToCustomRegion

    The caret rests at the comment line opening the region in question.

See Also

Procedures:

External Links:

Web Resources: