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 filenamesearches each directory in'path'for a file matching the name- Tab-complete the filename after
:findto cycle through matches - Wildcards are supported:
:find *.goor:find user*narrows results - The
pathoption 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.vimrcto recursively search from the current directory (use with caution in huge repos) :sfindopens the file in a horizontal split;:vert sfindin a vertical split:tabfindopens the file in a new tab- The
'suffixesadd'option lets:findtry appending extensions automatically (e.g.,.go,.py) so you can omit them