I'm getting one or more of these message when I open up a file I fold with a custom foldexpr function:

Pattern not found: lastlevel = -1

I'm not sure what's generating except the lastlevel variable is used in my fold function:

let g:lastlevel=0
function! Fold(lnum)
  " is line blank?
  if getline(a:lnum) =~? '\v^\s*$'
     if GetLevel(a:lnum + 1)
         g:lastlevel = -1
         return -1
     return g:lastlevel
  let last = g:lastlevel
  let num_of_pounds = GetLevel(a:lnum)
  if (num_of_pounds > 0)
     let g:lastlevel = num_of_pounds
     return '>' . num_of_pounds
  return g:lastlevel

function! GetLevel(lnum)
  let pounds = strlen(matchstr(getline(a:lnum), '^#\+'))
  return pounds

I also have this related autocommand:

augroup persist_markdown_folds
autocmd BufWinLeave *.md mkview
autocmd BufWrite *.md mkview
autocmd BufEnter *.md set foldenable | set foldlevel=0 | set foldmethod=expr | set foldexpr=Fold(v:lnum) | loadview
autocmd BufNewFile *.md set foldenable | set foldlevel=0 | set foldmethod=expr | set foldexpr=Fold(v:lnum)
augroup end
g:lastlevel = -1

let is missing. I suggest you use syntactic check plugin such as ale or syntastic .

  • 1
    This answer would benefit from an explanation of why the given line caused the error (answer: g:lastlevel is a global command searching for lastlevel) – D. Ben Knoble May 5 '19 at 1:53

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.