Is there any way to search a directory recursively for a file (using wildcards when needed) in Vim? If not natively, is there a plugin that can handle this?
Quickfix-like result browsing
Usage:
Find my.regex
Outcome:
grep -E
regex
or gf
to open the file on the current line in a new tabgf
to open the file on the current tab and lose the file listFind all files instead:
Find
Alternative methods:
Gfind my.regex
: only search for Git tracked files (git ls-files
). Fugitive request: https://github.com/tpope/vim-fugitive/issues/132#issuecomment-200749743Gtfind my.regex
: like Gfind
, but search from the git Top level instead of current directoryLocate somefile
: locate
versionCode:
function! Find(cmd)
let l:files = system(a:cmd)
if (l:files =~ '^\s*$')
echomsg 'No matching files.'
return
endif
tabedit
set filetype=filelist
set buftype=nofile
" TODO cannot open two such file lists with this. How to get a nice tab label then?
" http://superuser.com/questions/715928/vim-change-label-for-specific-tab
"file [filelist]
put =l:files
normal ggdd
nnoremap gf
execute 'autocmd BufEnter lcd ' . getcwd()
endfunction
command! -nargs=1 Find call Find("find . -iname '*'" . shellescape('') . "'*'")
command! -nargs=1 Gfind call Find('git ls-files | grep -E ' . shellescape(''))
command! -nargs=1 Gtfind call Find('git rev-parse --show-toplevel && git ls-files | grep -E ' . shellescape(''))
command! -nargs=1 Locate call Find('locate ' . shellescape(''))