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.

Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
jnicklas
  • 2,155
  • 2
  • 16
  • 14
  • 1
    What completefunc are you using? – Randy Morris Jan 30 '10 at 22:54
  • 1
    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. – falstro Mar 15 '10 at 15:15

3 Answers3

122

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.

Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
falstro
  • 34,597
  • 9
  • 72
  • 86
  • Thank you so much. This is one of these underexposed bughly relevant config options that are not mentioned in 'insert.txt' help – sehe May 13 '11 at 14:18
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...

eckes
  • 64,417
  • 29
  • 168
  • 201
  • 1
    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? – Legion Feb 05 '12 at 22:17
  • 1
    This worked for me, too. And again, "why on earth is foldmethod being called like crazy when Vim is doing autocomplete?"!! – Jason May 29 '12 at 17:58
  • 2
    I'd give a +5 if I could. Shout out to [this blog](http://economyofeffort.com/2012/03/01/fixing-slow-vim-auto-completion-with-ruby-files/) for pointing me here. – Kelvin Jul 26 '12 at 18:06
  • Btw, this also helped speed up opening of large files. – Kelvin Jul 26 '12 at 18:15
  • 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. – Yogeshwer Sharma Jun 14 '14 at 00:36
  • What the hell, this solved my issue... Do I really have to choose between folding and word-completion in a 400 line text file? – Hubro Dec 07 '15 at 07:21
  • @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? – eckes Dec 07 '15 at 07:29
  • 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. – borod108 Oct 22 '18 at 07:02
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.

Farrel
  • 2,383
  • 18
  • 14