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

How do I configure Vim to find files recursively in subdirectories?

Answer

:set path+=**

Explanation

Adding ** to the path option tells Vim to search recursively through all subdirectories when using :find, gf, and other path-related commands. This turns Vim's built-in :find into a powerful fuzzy-file-opening tool without plugins.

How it works

  • path — list of directories to search for files
  • ** — means "search recursively in all subdirectories"
  • :find filename — opens a file found anywhere in the path
  • Tab completion works with :find — type partial name and press <Tab>

Example

set path+=**

" Now you can find any file recursively
:find main.py<Tab>
" Completes to: src/app/main.py

:find *.test.js<Tab>
" Shows all matching test files
Project structure:
src/
  app/
    main.py
    utils.py
  tests/
    test_main.py

:find test_main.py → opens src/tests/test_main.py

Tips

  • Combine with wildmenu for a visual completion menu: :set wildmenu
  • Exclude directories: :set wildignore+=**/node_modules/**,**/.git/**
  • gf (go to file) also uses path — it finds files referenced in code
  • For large projects, a fuzzy finder plugin (fzf, telescope) is faster than **

Next

How do I return to normal mode from absolutely any mode in Vim?