I've noticed that vim's fold method affects the efficiency of autocomplete, e.g. C-N
is slow, and C-X L
is hideously slow in medium sized files with relatively expensive foldexpr
s.
I can't see the value in having foldexpr consulted while running through auto completes, so would like to disable this somehow so I get usable autocomplete back.
Any suggestions?
EDIT: some tests show:Test case
Make a file with one character per 100 lines, do a
<C-X>L
- the foldexrp is evaluated about 150 times.Make a file with ten characters per 100 lines, do the same - the foldexpr is evaluated about 7,500 times!
A test case: No plugins; and only this, which must be the most minimal foldexpr function possible (and is completely useless, except for counting invocations) in .vimrc
:
let g:c = 0
function! Myfoldexpr()
let g:c = 1 + g:c
return '=''0'
endfunction
Then make a fileNow start vim with 10a blank document. We'll copy the first 100 lines of Vim's own help file, and then run autocomplete line, choosing the 10th suggestion, then see how many times foldexpr was called.
:set fdm=expr help
y100j:q
P:set foldexpr=Myfoldexpr()
:echo g:cset fdm=expr
It will say 11.
zx O<C-X><C-L><C-L><C-L><C-L><C-L><C-L><C-L><C-L><C-L><C-L><Esc>
:echo g:c
2088
it will say 22
Now editthat's a new100 line file, with relatively short lines and pressthe foldexpr was called 2088 times (although 100 of these are done when first setting the foldexpr). Efficient foldexpr is obviously good, but we programmers ask a lot of our foldexpr, so they are necessarily non-trivial, and when their execution time is multiplied by several thousand it makes you choose between autocomplete or indent for productivity. Being greedy/lazy I'd like to be able to use both! Beyond attempting to rewrite several pretty well established foldexpr-based folding plugins (I've tried rewriting php-folding and after days of trying to optimise it to a workable state I gave up on foldexpr for php), perhaps there's a way to use a mapping to turn <C-X>Lfdm=manual
before autocomplete or some such?
:echo g:c
it now says 33 or 34