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

How do I restrict keyword completion to current buffer, windows, buffers, and tags for predictable results?

Answer

:set complete=.,w,b,t

Explanation

Default keyword completion can feel noisy in large projects because Vim may scan extra sources you do not care about in the moment. The complete option controls exactly where <C-n> and <C-p> pull candidates from. Tightening it to open-text sources plus tags gives faster, more relevant completion with less random vocabulary bleed.

How it works

  • . searches the current buffer
  • w includes buffers visible in other windows
  • b includes loaded buffers
  • t adds tag-based completion from your tags files

By explicitly setting complete=.,w,b,t, you exclude slower or noisier sources (like include-file scanning or unloaded buffers), which keeps completion deterministic during refactors and large multi-file sessions.

Example

Project contains many generated files and vendor code.
Default completion offers irrelevant identifiers.

Apply:

:set complete=.,w,b,t

Now <C-n> prioritizes terms from currently active editing context and tags, reducing accidental completions from distant files.

Tips

  • Add u if you also want unloaded buffers searched
  • Temporarily inspect current value with :set complete?
  • Pair with :set wildmenu and tag generation for stronger symbol completion workflows

Next

How do I get exact current and total counts for my last search pattern in Vim?