How to fold all comments in PyCharm
Asked Answered
A

4

14

I've recently been editing files with a lot of long comments. I find myself folding lots of them manually, is there a way to fold all of these at once, using some kind of menu entry or keyboard shortcut?

Alitta answered 14/2, 2016 at 14:25 Comment(2)
Try Code | Folding | Collapse doc commentsSmashing
@Smashing Really strange but it didn't do anything for me, I tried 2 different projects, both with all text selected and no text selected. Does it usually work for you? This is pycharm 5.0.4.Alitta
A
13

As of writing (version 2016.2.3) there's no way to collapse just comments.

The closest is the Code > Folding > Expand all to level menu items, but that folds everything by level. There are 5 levels available, with keyboard shortcuts:

  • Ctrl+Shift+Numpad *, 1 (Press Ctrl+Shift+Numpad *, then press 1. On macOS substitute Command for Ctrl)

    enter image description here

  • Ctrl+Shift+Numpad *, 2

    enter image description here

  • Ctrl+Shift+Numpad *, 3

    enter image description here

  • Ctrl+Shift+Numpad *, 4

    enter image description here

  • Ctrl+Shift+Numpad *, 5

    enter image description here

Aporia answered 7/12, 2016 at 0:14 Comment(0)
R
5

I came to this question recently with the same one, but I've ince found it is possible to do this in recent pycharms. In pycharm 2020.3 (and possibly earlier versions, but that's the one I'm using), there is now an option to "Collapse Doc Comments", which appears to do what you need! It collapsed all the docstring comments in my file and ignored all other collapsible portions of code.

Code -> Folding -> Collapse Doc Comments

enter image description here

Richrichara answered 17/5, 2021 at 13:55 Comment(1)
+1. From my first comment I don't think it worked many years ago, but it now appears to work fine for me, so guessing they fixed some bug. However it doesn't appear to work for long multi-line comments, which can be manually collapsed one-by-one.Alitta
A
2

Press (Command) and +(key) to expand and use -(key) to collapse

Anet answered 15/2, 2016 at 17:56 Comment(2)
Thanks, but I would like a solution for all comments.Alitta
Goto Code>Folding and there you can select the level of folding which you preferAnet
A
-2

try shift+ctrl+= Expand all folding regions.

Aloin answered 9/8, 2019 at 7:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.