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

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 wildmenu and :set wildmode=longest:full,full for 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 :find command to work across subdirectories, also set :set path+=**
  • wildignore does not affect :vimgrep file patterns that are explicit paths — only those that use wildcards

Next

How do I build a macro programmatically using Vimscript instead of recording it?