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

How do I open a file by name without knowing its full path?

Answer

:find

Explanation

The :find command searches for a file by name across all directories listed in Vim's path option, so you can open files without typing full paths. Combined with wildcard expansion and tab-completion, it becomes a lightweight fuzzy-file opener — especially useful in large projects.

How it works

  • :find filename searches each directory in 'path' for a file matching the name
  • Tab-complete the filename after :find to cycle through matches
  • Wildcards are supported: :find *.go or :find user* narrows results
  • The path option defaults to . (current dir) and an empty string (current file's dir). Add project roots with :set path+=src/** to search recursively

Example

Suppose your project has src/models/user.go. With:

:set path+=src/**

You can open it with:

:find user.go

Or use tab-completion to explore matches:

:find user<Tab>

Tips

  • Add set path+=** in your .vimrc to recursively search from the current directory (use with caution in huge repos)
  • :sfind opens the file in a horizontal split; :vert sfind in a vertical split
  • :tabfind opens the file in a new tab
  • The 'suffixesadd' option lets :find try appending extensions automatically (e.g., .go, .py) so you can omit them

Next

How do I match a pattern only when it is preceded or followed by another pattern, without including that context in the match?