How do I find all files matching a pattern across all directories in Vim's runtimepath?
Answer
globpath(&rtp, 'pattern')
Explanation
globpath() is a Vimscript function that searches all directories in a given path list for files matching a glob pattern. When you pass &rtp (the value of runtimepath) as the first argument, it searches every directory Vim knows about — installed plugins, system runtime, and your personal config — making it ideal for discovering files, writing conditional logic, or debugging your configuration.
How it works
globpath(pathlist, pattern)— searches each directory in the comma-separatedpathlistforpattern&rtp— reads the currentruntimepathoption value- Returns a newline-separated string of matching file paths
- Pass
0, 1as extra arguments to get a List instead of a string
Example
Find all ftplugin/python.vim files across the runtimepath:
:echo globpath(&rtp, 'ftplugin/python.vim')
/usr/share/vim/vim91/ftplugin/python.vim
~/.vim/ftplugin/python.vim
Get all installed colorscheme names as a List:
:let schemes = map(
\ globpath(&rtp, 'colors/*.vim', 0, 1),
\ 'fnamemodify(v:val, ":t:r")')
:echo schemes
Tips
- Use the List form for cleaner iteration:
globpath(&rtp, 'plugin/*.vim', 0, 1) - Check for optional features:
if !empty(globpath(&rtp, 'plugin/fugitive.vim'))— but note:packaddmay not have loaded it yet glob()is simpler for single-directory searches;globpath()is for multi-directory path lists- Works with any path string, not just
&rtp:globpath(&packpath, 'pack/**/start/*', 0, 1)lists all packages