3

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

bad_coder
  • 11,289
  • 20
  • 44
  • 72
Salvador Dali
  • 214,103
  • 147
  • 703
  • 753

2 Answers2

7

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 + .

Salvador Dali
  • 214,103
  • 147
  • 703
  • 753
2

Comment folding has been available for a while now. Any multi-line comment, regardless of type (#, """), will cause clickable folding icons to show up.

enter image description here

The #region feature is still useful, if you want to fold mixed content.

congusbongus
  • 13,359
  • 7
  • 71
  • 99