3

I greatly make use of Vim's <C-n>/<C-p> auto-completion menu. When working on large projects, or on sporadic large files, this may take several seconds or longer to be populated.

Is there some way to have Vim populate the menu as it finds the results, or to otherwise make the menu appear faster (note that I make heavy use of suggestions from unloaded buffers, of the default complete setting .,w,b,u,t,i)?

1

1 Answer 1

2

There is no "speed up the completion menu"/"make the completion menu async"/"make the completion menu use a cache" option, if that's what you are hoping for, so you basically have three options:

  • write/use some custom completion function that behaves the way you want,
  • or figure out what is causing those delays and see if fine tuning your :help 'complete' value helps,
  • or open an issue in Vim's issue tracker and see if it gets enough traction.

Fundamentally, the issue is the same as with the wildmenu: gathering suggestions may be one possible bottleneck but building the menu is definitely the main bottleneck.

Opening all *.c files from the Vim source with $ vim **/*.c, I get 190 buffers, some of them infamously "large".

If I open a new line with o and press <C-n> without any text in the front, it takes about 25 seconds for the menu to be displayed, here (YMMV). Vim went through 190 buffers and god knows how many includes to build a very large list containing every keyword it found and then built the menu from that list.

If I do <c-n> more responsibly, after something like defi, the completion menu is displayed with a sub-second delay. Vim went through the exact same buffers and files as above but it built a much smaller menu from a much smaller list, much faster.

Basically, the larger the menu, the longer it takes Vim to build it, and I suspect that the progression is not even linear.

So, to sum it up…

  • There is no user-facing way to change how the menu for the built-in <C-n> is built.
  • Adjusting the completion sources may help but not by much because the problem is elsewhere.
  • Using <C-n> responsibly (for completion vs exploration) helps a lot.
  • Writing your own completion function that builds the menu incrementally could probably work but it doesn't sound particularly trivial. See :help compl-function.
  • Petitioning the dev team might work but submitting a patch seems to be the best, forward-thinking move. Not trivial either.
1
  • That's so sad... Time to dive into the vim source, I suppose. At least I'm glad it looks quite clean. Sep 5, 2023 at 9:24

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.