How do I open a file found in Vim's path setting in a new split without typing the full path?
Answer
:sfind {file}
Explanation
:sfind (split-find) searches Vim's path setting for a file matching the given name and opens it in a new horizontal split, all in one command. It combines the file-discovery power of :find with :split, so you do not need to know where the file lives as long as its directory is in path.
How it works
:sfind {name}— searchespathfor{name}, opens in a horizontal split:vertical sfind {name}— same, but opens in a vertical split- Tab completion works: type
:sfind Par<Tab>to complete file names found inpath - Wildcards are supported:
:sfind *.hopens the first matching header in a split
Example
With set path+=** (to search recursively from the current directory):
" Open utils.py in a split without navigating to it first
:sfind utils.py
" Open it vertically with tab completion
:vertical sfind util<Tab>
Compare the family of find commands:
:find utils.py " open in current window
:sfind utils.py " open in horizontal split
:vertical sfind utils.py " open in vertical split
:tabfind utils.py " open in a new tab
Tips
- Set
set path+=**in your vimrc to search recursively from the project root set wildmenumakes tab-completion of file names interactiveset suffixesadd=.py,.js,.tslets:sfindfind files without typing the extension:findand:sfindrespectset wildignoreto skip unwanted files likenode_modules