Vim's autocomplete is excruciatingly slow
Asked Answered
E

3

70

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.

Embouchure answered 30/1, 2010 at 22:10 Comment(2)
What completefunc are you using?Weinhardt
I have the same problem, but in C++. Did you get this under control? I've tried playing around with and without tags-files, but it keeps scanning the current directory recursively (I straced it, to see what it's doing, and it keeps calling stat on all files it can find). It's a clearcase environment == slooooow.Mathur
M
123

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.

Mathur answered 17/3, 2010 at 7:53 Comment(1)
Thank you so much. This is one of these underexposed bughly relevant config options that are not mentioned in 'insert.txt' helpTriumph
A
47

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...

Arriaga answered 25/11, 2010 at 13:11 Comment(8)
YOU ARE AWESOME. Completion in Ruby files was unusably slow for me, in files that were fairly trivial in size (~100 LOC). Couldn't solve it. Then I read this. I change foldmethod in a Ruby buffer to anything besides "syntax" and completion happens instantly. Now, why on earth is foldmethod being called like crazy when Vim is doing autocomplete?Orndorff
This worked for me, too. And again, "why on earth is foldmethod being called like crazy when Vim is doing autocomplete?"!!Isaacs
I'd give a +5 if I could. Shout out to this blog for pointing me here.Telltale
Btw, this also helped speed up opening of large files.Telltale
This was so helpful for me. It was so hard to debug this issue! I was using vim profiler (!profile start ...) but that did not turn anything up. :( Thanks so much.Bukhara
What the hell, this solved my issue... Do I really have to choose between folding and word-completion in a 400 line text file?Turret
@Hubro: seems so, yes. But honestly, I never really used folding anyways... And maybe other completers (e,g YCM aka YouCompleteMe) behave different than ACP?Arriaga
Thank you it did the trick for me!!! Just stating the obvious here: you can run :set foldmethod=manual to test it out for yourself.Athalia
P
6

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.

Palestrina answered 30/1, 2010 at 22:24 Comment(2)
ctags -R in your project root; is the command if you are on linuxMetronome
or more specifically: ctags -R -n --fields=+i+K+S+l+m+a --exclude=src/react/conf-srch/node_modules .Fly

© 2022 - 2024 — McMap. All rights reserved.