Best method for folding Python code (or other way to browse)?

I want aggressive code folding in Python.

I want folded code to read like a structured table of contents that I can just directly dive into by opening folds. I don’t want anything smaller than function/method definitions folded (no folding brackets or if, while, etc.). I want python @properties and docstrings folded with their methods/classes/etc. When fully-folded, I really just want functions, classes, methods, other class attributes, and all top-level variables/code to show up, and no whitespace except between non-class non-function top-level code (I can comment a line, if I want whitespace there).

vim-coiled-snake is really, really close to what I want (I’d like it to fold more whitespace), but it makes the editor so slow it’s unusable (it sometimes takes 10+ seconds to delete a single line).

Folding all code with zM, jumping around, then unfolding code as I find what I’m after just feels like the “right” way to browse code, and it’s how I interact with vim most often. It seems so obvious, that I can’t believe it’s so hard to find a working solution. It makes me wonder, am I trying to do something dumb? Is there a better way? Is there a working solution I don’t know about?

Hi, @ipsod

I’m not sure if I’m understanding what you are saying correctly, but you might try the following plugin.

Hi! That looks like it could work better than nothing, so I’ll give it a try.

Would it make more sense if I said I want folding to hide everything not essential to getting an overview of the code’s structure? I don’t like the context jump between code-itself and a navigator with an abstract representation of the code. I find it mentally expensive - it doesn’t flow. Also, these navigators all hide so much information that I’d actually like to see (arguments, return value type, single-line comments, etc.), and if they didn’t, they’d take up too much screen real-estate.

This is how folding currently is, with decorator lines cluttering and unnecessary whitespace that makes getting an overview require a lot of scrolling:

This is how I want it to be (though if it kept highlighting while folded, like nvim-ufo, it’d be better):