Trying to figure out why folds aren't happening as soon as I open a file:

set foldenable
set foldmethod=expr
let g:lastnum = 0
function! FoldFile(lnum)
    echom 'hi';
    if getline(a:lnum) =~? '\v^\s*$'
    let g:lastnum = -1
        return '-1'
    let last = g:lastnum
    let num_of_pounds = strlen(matchstr(getline(a:lnum), '^#\+'))
    if (num_of_pounds > 0)
            let g:lastnum = num_of_pounds
        if last == -1
            return '>' . num_of_pounds
        return num_of_pounds
    return g:lastnum
set foldlevel=0
set foldexpr=FoldFile(v:lnum)

To get the folds to kick in, I have to source my ~/.vimrc file

  • Ah, dammit, a plugin is setting foldmethod to manual. How do I override this behavior? – StevieD Apr 28 at 21:07
  • depends on the plugin. Curious: are you sure you always want exactly this fold setup, irrespective of filetype? – D. Ben Knoble Apr 29 at 1:49
  • No, I don't. I'm mostly focused on just getting basic stuff working at this point and trying to figure out why stuff doesn't. – StevieD Apr 29 at 2:02
  • Ok. So, what plugin overrides it? Have you considered putting this stuff in an after/ftplugin file? For folds i usually go with after/ftplugin/{filetype}/folds.vim – D. Ben Knoble Apr 29 at 2:13
  • Vimwiki. I couldn't even override it because it overrides it when the buffer loads. Resorting to making a patch to the plugin (or trying to, at least): github.com/vimwiki/vimwiki/pull/692 – StevieD Apr 29 at 2:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.