I want to make a custom folding method for python scripts. I want to fold everything that starts with “# %%”. I wrote the following function:
" Custom Folding for python function! BlockFolds() let thisline = getline(v:lnum) if match(thisline, '# %%') >= 0 return ">1" else return "=" endif endfunction
autocmd BufEnter *.py set foldmethod=expr
autocmd BufEnter *.py set foldexpr=BlockFolds()
It works but then neovim becomes extremely slow for files with 1000+ lines. I have neovim 0.5 nightly.
Is there a better way to do it? Is there any plugin that I can use? Can I write the same function in lua?
Thank you in advance for your help.