I am trying to use expr fold in vim: I create a file in ~/.vim/ftplugin/python/folding.vim and its' content:
setlocal foldmethod=expr
setlocal foldexpr=GetFold(v:lnum)
function! GetFold(lnum)
if a:lnum > 10
return 1
endif
return 0
endfunctio
this 'GetFold' function is a simple version for test
however when I open a python file, the fold does not work, no folding occurred, while I expect the lines over 10 should fold
the python file content:
import numpy
import numpy as np
def tm(a):
a += 1
print(a)
class _A_3(object):
def __init__(self):
x = 1
y = 1
z = 1
def update(self):
x = 2
y = 2
z = 2
if __name__ == '__main__':
arr = np.array([1,2,3],dtype=np.float64)
print(str(type(arr)))
tm(0)
ta = A()
I checked the filetype, :set filetype?
it shows filetype=python
, so filetype no problem.
I checked the foldmethod, :set foldmethod?
it shows foldmethod=expr
, so foldmethod no problem.
I checked if the 'GetFold' function exists and works correctly:
:echom GetFold(5)
it shows 0
, :echom GetFold(12)
it shows 1
, so 'GetFold' function seems ok.
I use vim's 'foldlevel()' function to check:
:echom foldlevel(5)
it shows 0
, :echom foldlevel(11)
it shows 0
,
:echom foldlevel(15)
it shows 0
also.
So, it seems vim does not set the foldlevel by my function, I can't figure out where is the problem. I checked the :help fold-expr
, but I think follows the instruction as it says:
change 'GetFold' return from 1,0 to '1','0' and line 11's return to '>1' dose not help.