I am trying to write a completion function which has as its source a 386k line (CSS) file.
Initially I read the file into a list with
readfile() and used a
for loop to iterate over each line, matching it against the base text. This worked but took about 5-7 seconds. (
readfile() was very quick; the time was spent in the loop.)
I couldn't see a way to speed that up so instead I tried loading the file into a buffer and using
search() to find the matches. I coded it up with a hardcoded string pattern and it was very fast - a few hundred milliseconds at most.
So then I tried using that in my completion function but ran into a problem. To search the big file I switch to its buffer, do the search stuff, then switch back to the previous buffer. But during insert-mode completion it is not allowed to switch buffers.
Is there a way to run commands or a function in a hidden buffer without switching to it?