How do I exclude compiled files and dependency folders from Vim's file name completion?
Answer
:set wildignore+=*.pyc,*.o,node_modules/**,.git/**
Explanation
wildignore is a comma-separated list of glob patterns that Vim skips when expanding file names. Without it, pressing <Tab> after :e or :find surfaces thousands of compiled artifacts, cache files, and dependency directories that you never want to open manually.
How it works
:set wildignore+=— appends to the existing list so you don't wipe any defaults- Patterns follow Vim's glob syntax:
*matches any number of characters,**matches recursively across directories - Affects
:e,:find,:args,:vimgrep,:r, and any other command that completes file paths - Does not affect the ability to open files by full path — it only filters completion candidates
Example
Add to your ~/.vimrc:
set wildignore+=*.pyc,__pycache__/** " Python bytecode
set wildignore+=*.o,*.a,*.so " compiled objects
set wildignore+=node_modules/** " JS dependencies
set wildignore+=.git/**,.hg/** " VCS metadata
set wildignore+=*.swp,*.swo " Vim swap files
Now :find src/<Tab> lists only source files, not Git objects or compiled output.
Tips
- Pair with
:set wildmenuand:set wildmode=longest:full,fullfor a navigable completion menu - Check current value with
:set wildignore?— the list can grow long and it is easy to forget what is excluded - For the
:findcommand to work across subdirectories, also set:set path+=** wildignoredoes not affect:vimgrepfile patterns that are explicit paths — only those that use wildcards