Search code examples
pycharmfoldingcode-regions

Folding of comments in PyCharm


For a long time I was looking for a way to fold comments in PyCharm. Basically I was looking for a way to achieve the same + for comments as for the block of code.

screenshot of code in editor


Solution

  • It is easy to achieve this with

    #region Description 
    # all your comments go here
    #endregion 
    

    or this:

    // <editor-fold desc="Description"> 
    // all your comments go here
    // </editor-fold> 
    

    Important thing to remember is that you can not mix both kinds of folding.

    Also instead of typing all these #region Desription you can just press CRTL+ALT+T (but not on ubuntu, where this combination is for opening terminal) or going to Code -> Surround With and selecting your surrounding type.

    Using this type of surrounding you can fold any arbitrary parts of the code. But you can also do this with CTRL + .