I want to collapse functional definitions in python code using a framework based on Vim syntax. So I added the following to my .vim / syntax / python.vim:
setlocal foldmethod=syntax syn sync fromstart syn region pythonFunctionFostart="^\z(\s*\)\%(def\|class\) " skip="^\s*$" end="^\ze\%(\z1\s\)\@!." fold transparent
It works; it also absorbs blank lines between functions (unlike foldmethod = indent) that I want. However, I do not want the string def def (): "to be collapsed. As far as I understood the docs, I could do the following:
syn region pythonFunctionFold start="^\z(\s*\)\%(def\|class\) .*\n\zs." skip="^\s*$" end="^\ze\%(\z1\s\)\@!." fold transparent
But this forces vim to not create any fouls at all. (I tried to run the regex using simple search and it works). None of them work:
syn region pythonFunctionFold start="^\z(\s*\)\%(def\|class\) .*\n."ms=e skip="^\s*$" end="^\ze\%(\z1\s\)\@!." fold transparent
and hs = e, rs = e
Everything that I try either includes def or does not work at all. (I think vim doesn't like newlines inside my regexps syntax). Is there an easy way to make the syntax reset the beginning of a line after matching a regular expression?
Edit: I also tried the following:
syn match pythonFunctionFold "^\(\s*\)\%(def\|class\) .*\n\zs\(\s*\n\|\1\s\+.*\n\)\+" fold transparent
When I search for a template (using /), it exactly matches the regions I want to reset, and " :help syntax " claims support for multi-line matches. But I'm still not folding.
source share