I use foldmethod=expr with the following foldexpr: set foldexpr=GetFoldLevel(v:lnum)
function! GetFoldLevel(line) let line_text = getline(a:line) if (line_text =~ '\%({.*}\)\|\%(}.*{\)') return '=' elseif (line_text =~ '{') return "a1" elseif (line_text =~ '}') return "s1" endif return '=' endfunction What I want to do is similar to foldmethod=marker with foldmarker={,}, but if I use foldmethod=marker vim gets confused by lines that contain both { and } like these: string s = String.Format("{0}", v); string[] sa = new string[] { "a", "b" }; GetFoldLevel() above fixes that, in that it keeps the same fold level if both { and } are found on the same line, but it is horribly slow. Even in pretty small files (1k lines long), it can take several seconds for characters to appear when I'm typing in insert mode. Is there a way to optimize the above, or an alternative way of doing this? It is very frustrating to have my folds get out of whack with foldmethod=marker, but the slowness of this foldexpr is unbearable. -- Be seeing you.