0

In some of my projects, vim autocomplete is very quick, but in other projects it hangs the editor while displaying a status line "examining file ..." that slowly crawls through all the files in the project. Is this simply caused by the size of the project, or is there a cache that is somehow not working? If this is simply a limitation of the feature, I'd appreciate any suggestions for an autocomplete plugin that may be more efficient.

> uname -svr
Linux 5.13.4-200.fc34.x86_64 #1 SMP Tue Jul 20 20:27:29 UTC 2021

> vim --version
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Jul 19 2021 00:00:00)

:set complete
complete=.,w,b,u,t,i 
1
  • I’m not aware of any built-in cache. Certain autocompletion sources/plugins/functions may do this, but caching is hard
    – D. Ben Knoble
    Commented Nov 7, 2021 at 22:48

1 Answer 1

2

Instead of caching, you can try some techniques to avoid searching through so many files.

  1. Because the 'complete' setting applies to completion triggered by ctrl-p or ctrl-n, try one of auto-complete modes triggered by ctrl-x.
    For instance, ctrl-x ctrl-n is keyword completion only for the current buffer. This will avoid searching through all other buffers and included files for keywords.

  2. The i option in complete=.,w,b,u,t,i is probably the big time consumer. That tells Vim to search through all included files (recursively).
    If you don't want completion from included files, then remove i:

set complete-=i
  1. If you do want some included files but want to exclude others, then you might be able to play with the 'path' and 'includeexpr' settings so Vim doesn't locate some included files.
2
  • Is there a way to limit the frequency of import scanning, at the cost of potentially missing some recent keywords? It would be nice to have the majority of those keywords available. But you are correct that the delay is caused by scanning imports every time. So far the whole autocomplete feature is much more usable with set complete-=i. Commented Jan 13, 2022 at 18:48
  • There's no Vim setting built in for that. There are many plugins available that might be more useful....or you could write your own. See :help complete-functions as a start. I would recommend when calling the function for the first time to scan all the included files and cache all keywords in memory. Save the result of localtime(). On subsequent calls to the function, use getftime() to see if any included files have been updated since last time. If no files have been updated, then use the keyword list already in memory. Otherwise, re-load the edited files. Commented Jan 13, 2022 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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