How do I control which sources Vim searches when triggering keyword completion with Ctrl-N?
Answer
set complete=.,w,b,u,t
Explanation
The complete option controls which sources Vim scans when you press <C-n> or <C-p> for generic keyword completion. Each comma-separated flag adds a source. Understanding and customizing this option lets you make completion faster or more comprehensive depending on your workflow.
How it works
The default value is .,w,b,u,t,i. Each flag means:
.— the current bufferw— buffers visible in other windowsb— other loaded buffers in the buffer listu— unloaded buffers in the buffer listt— tag files (ctags)i— files included by the current file (e.g.,#include)k— dictionary file(s) set in'dictionary'kspell— active spell check wordlist
Example
For prose writing, add spell-check words to completion:
set complete+=kspell
For a large codebase where tag lookups are slow, narrow down to just the current and other buffers:
set complete=.,b
For Vimscript development, include built-in definitions:
set complete+=d
Tips
- Use
complete+=kspellcombined withset spellfor natural language writing —<C-n>will suggest correctly-spelled words - Remove
tfromcompletewhen you have a large ctags database and don't want it slowing down every<C-n>press <C-x><C-k>triggers dictionary-only completion regardless of thecompletesetting<C-x><C-n>scans only the current buffer regardless ofcomplete