I'm not sure about a plugin or automation, but if you type zf/
you can then search for something and it will fold up to the next instance of it. So in a document like the following (where [] is the cursor):
def foo():
"""[]
Some long docstring
that takes up many
lines
"""
pass
Look at edit2 first for the updated search string!
If you use the command zf/"""[ENTER]
, it should fold everything from the current line (the beginning of the docstring) to the next occurrence of """
which should be the end of the docstring.
I know this isn't automation, but perhaps it will help in the interim, or lead you down the right path to automating it. See edit2 for a better search function, although I still don't know how to automate.
Hope this helps.
Edit: in a corollary, you can search for any docstring with /"""\_.\{-}"""
, although this will also return the code within the docstring. To search for a function definition followed by a docstring, you can use /def\_.\{-}"""\_.\{-}"""
, although this breaks on a def inside the docstring.
Edit2: Actually, some more playing with regexs led me to this: /def.\{-}):\_s*"""\_.\{-}"""
which should find any function followed by a docstring. It searches for def
followed by any characters, then ):
followed by a newline and/or whitespace followed by """
followed by any number of lines than the next """
, but always ensures the 2nd triple quote is the one immediately following the first.