Vim's autocomplete is excruciatingly slow

VimAutocompleteCode Completion

Vim Problem Overview


Most of the time the autocomplete feature in Vim works nicely for me, but sometimes it seems to be scanning files which the current file references, and then it becomes painfully slow, sometimes taking several seconds to release focus back to me.

Sometimes Vim tells me simply that it is "Scanning" other times, it's saying "Scanning tags"

I've only this happen in Ruby files, and it happens mostly when there is a require in the file.

My guess would be that this is some kind of feature which checks related files for autocomplete options, but I don't really need that, and would prefer quicker autocomplete.

Vim Solutions


Solution 1 - Vim

As I mentioned in a comment I had the same problem. Here's what I found;

There's a setting telling VIM where to look for completions, called complete.

:set complete
complete=.,w,b,u,t,i

this is the default value. My problem is (was actually..) the 'i', which scans all included files. Here are two problems, first one, finding all those files might take quite a while, especially if you, like me, have

:set path=**

Second problem, once found, they need to be read, and if you're using a networked file system (I'm on clearcase) both finding and reading all those files might trigger cache misses, making it painfully slow.

I've removed the i for now, as I have a tags-file and more often than not, I also have the relevant files in my buffers (loaded or unloaded) which will be searched as a result of 'b' and 'u'.

Use

set complete-=i

to remove the i from the list, note that this is local to the buffer.

Solution 2 - Vim

Had a very similar problem since upgrading to Vim 7.3 (from 7.2): I was using the (excellent) ACP plugin and in longer source files (C-files, 1700 LOC), the popup took ages to jump through the suggestions when I was editing near the bottom of the file.

Using the PerformanceValidator (from Softwareverify), I found out that some fold methods were called again and again and lead to very high processor load and slow completion.

My workaround was to set the foldmethod (fdm) to manual. And this solved it...

Solution 3 - Vim

Do you have a tags file for the project you're working on? If not try generate one with exuberant-ctags and Vim should pick it up with the taglist pluglin.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjnicklasView Question on Stackoverflow
Solution 1 - VimfalstroView Answer on Stackoverflow
Solution 2 - VimeckesView Answer on Stackoverflow
Solution 3 - VimFarrelView Answer on Stackoverflow