# Folding lists in vimwiki with custom folding enabled

vimwiki's help docs, and this answer, both explain how setting g:vimwiki_folding='list' in my vimrc enables list folding for vimwiki files. This lets me use vim's native folding methods on vimwiki lists (e.g., zM to fold sublist items, zr to open folds, etc.)

let g:vimwiki_folding='list'


But a few lines down in the docs, I've followed instructions to enable blank lines between folded sections (which I prefer for readability), which required me to add the following to my vimrc:

let g:vimwiki_folding='custom'

function! VimwikiFoldLevelCustom(lnum)
let pounds = strlen(matchstr(getline(a:lnum), '^#\+'))
if (pounds)
return '>' . pounds  " start a fold level
endif
if getline(a:lnum) =~? '\v^\s*\$'
if (strlen(matchstr(getline(a:lnum + 1), '^#\+')))
return '-1' " don't fold last blank line before header
endif
endif
return '=' " return previous fold level
endfunction

augroup VimrcAuGroup
autocmd!
autocmd FileType vimwiki setlocal foldmethod=expr |
\ setlocal foldenable | set foldexpr=VimwikiFoldLevelCustom(v:lnum)
augroup END


Of course, the line let g:vimwiki_folding='custom' overwrites the earlier setting of 'list', so I lose list folding.

What can I do to keep my custom folding, but also re-enable list folding? Is there an edit I can make to the VimwikiFoldLevelCustom function to achieve this?

• Welcome to Vi and Vim! You may have more luck with the vimwiki maintainers; at any rate, if you could edit to include more details (from the help, the answer, or just code from what you're trying to accomplish), that would help make the question more self-contained. Leave the links, but we want to avoid link-rot and make it easier to see all the details in one place. – D. Ben Knoble Mar 5 at 13:58
• Thanks for the advice, I've updated the question. I came here first as there's quite a lot of open issues on their GitHub repo, so I figured I might get an answer faster here. But I'll head over there if there's no solution here soon. – murchu27 Mar 8 at 8:19