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: Test case
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
Now start vim with a 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.
:help
y100j:q
P:set foldexpr=Myfoldexpr()
:set fdm=expr
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
Now that's a 100 line file, with relatively short lines and the 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 fdm=manual
before autocomplete or some such?
iHello<Esc>
, theg:c
variable is also increased to20
, then doingoWorld<Esc>
makes it38
... So the number of evaluationsfoldexpr
seems unrelated to using completion... Try loading Vim with a minimal vimrc file and see if the problem still occurs, it could be another setting or a plugin.p
), I think what it's doing is doing it per character of the insert candidate.