vimtricks.wiki Concise Vim tricks, one at a time.

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

  • complete is a comma-separated list of single-letter flags specifying completion sources:
    • . — current buffer
    • b — other loaded buffers
    • u — unloaded buffers
    • iincluded files (the slow one)
    • t — tags (ctags)
    • w — buffers in other windows
  • complete-=i removes the i flag 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 vimrc alongside :set complete-=u to 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'

Next

How do I copy files to a target directory using netrw's marking system?