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

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 buffer
  • w — buffers visible in other windows
  • b — other loaded buffers in the buffer list
  • u — unloaded buffers in the buffer list
  • t — 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+=kspell combined with set spell for natural language writing — <C-n> will suggest correctly-spelled words
  • Remove t from complete when 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 the complete setting
  • <C-x><C-n> scans only the current buffer regardless of complete

Next

What built-in LSP keymaps does Neovim 0.10+ provide automatically when a language server is attached?