How do I speed up Vim's insert mode completion by disabling include-file scanning?
Answer
:set complete-=i
Explanation
Vim's complete option controls which sources are scanned when you press <C-n> or <C-p> to complete a word. By default, the i flag instructs Vim to scan all files reachable via include statements — useful for C/C++ projects but painfully slow in large codebases where headers span thousands of files.
Removing the i flag with :set complete-=i restricts completion to the current buffer, loaded buffers, and tags — all of which are already cached in memory.
How it works
completeis a comma-separated list of single-letter flags specifying completion sources:.— current bufferb— other loaded buffersu— unloaded buffersi— included files (the slow one)t— tags (ctags)w— buffers in other windows
complete-=iremoves theiflag while leaving the rest unchanged- The result is faster, more predictable completion
Example
Before (default value):
:set complete?
complete=.,w,b,u,t,i
After:
:set complete-=i
:set complete?
complete=.,w,b,u,t
Typing <C-n> in insert mode now completes instantly from buffers and tags without walking the include chain.
Tips
- Add this to your
vimrcalongside:set complete-=uto also skip unloaded buffers if you prefer even tighter control - View current sources at any time with
:set complete? - To fully understand all flags:
:help 'complete'