Hi, everyone
I want to create myself python folding style, for example
0
1 class Whatever:
1
2 def __init__(self):
2
2 pass
0
1 def whatever():
1
1 pass
so I edit my ~/.vim/ftplugin/python.vim, and add the following lines:
Code:
function! Python_fold_level(lnum)
let l:line = getline(a:lnum)
let l:indent = indent(a:lnum)
" folding for blank line
if l:line =~ "^$"
if getline(a:lnum-1) =~ "^$"
return "="
endif
let l:i = 1
while 1
let l:next_line = getline(a:lnum+i)
" start without space
if l:next_line =~ "^\s\@!"
return 0
endif
" start with indent
if indent(a:lnum+i) != 0
return "="
endif
let l:i += 1
endwhile
endif
" folding for class
if l:line =~ "^class"
return 1
endif
" folding for function
if l:line =~ "^\s*def"
return "a1"
endif
if l:indent != 0
return "="
endif
endfunction
setlocal foldexpr=Python_fold_level(v:lnum)
setlocal foldmethod=expr
setlocal foldclose=all
but the effect is not what I want, it looks like
0
1 class Whatever:
1
1 def __init__(self):
1
1 pass
1
2 def whatever():
2
2 pass
This is an incomplete script, please help me check it out.
Thanks for help!