How do I prevent Vim's file completion and wildcard expansion from matching build artifacts or binary files?
Answer
:set wildignore
Explanation
:set wildignore defines a comma-separated list of glob patterns that Vim excludes from wildcard expansion and file completion. By keeping compiled binaries, generated output, and dependency directories out of completion results, you get faster and cleaner navigation with :e, :find, gf, and tab-completion on the command line — all without plugins.
How it works
set wildignore+=*.o,*.pyc,*.class " compiled objects
set wildignore+=node_modules/,dist/,build/ " dependency and output dirs
set wildignore+=.git/,.hg/,.svn/ " VCS metadata
set wildignore+=*.jpg,*.png,*.gif,*.pdf " binary assets
- Patterns follow standard glob syntax:
*matches any string,?matches a single character,[...]matches a character class - Both files and directories are matched
- The
+=operator appends to the existing list, preserving any defaults - Affects:
:e,:find, tab-completion on the command line,expand()with globs, andglob()in Vimscript
Example
In a TypeScript project without wildignore:
:e src/<Tab> → src/app.ts src/index.ts node_modules/ dist/
After adding :set wildignore+=node_modules/,dist/:
:e src/<Tab> → src/app.ts src/index.ts
Tips
wildignorecase(:set wic) makes pattern matching case-insensitive on case-sensitive systems, useful on Linux when files might be namedMakefileormakefile- Pair with
:set path+=**to create a lightweight fuzzy-file-open workflow::find app<Tab>will search recursively and skip ignored paths - Inspect the current value with
:set wildignore? - Unlike
.gitignore,wildignoreonly affects Vim's internal file operations — it has no effect on:!shell commands or external tools