Created
September 4, 2025 11:34
-
-
Save rochacbruno/96ac5545f13f3eab8404fba0e1d335c3 to your computer and use it in GitHub Desktop.
Simple Fuzzy Finder for Vim9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vim9script | |
# simple fuzzy find finder | |
# place into ~/.vim/plugin/fuzzyfind.vim | |
set wildmode=noselect:lastused,full | |
set wildmenu wildoptions=pum,fuzzy pumheight=12 | |
cnoremap <Up> <C-U><Up> | |
cnoremap <Down> <C-U><Down> | |
cnoremap <C-p> <C-U><C-p> | |
cnoremap <C-n> <C-U><C-n> | |
nnoremap <space>f :<C-u>find<space> | |
var files_cache: list<string> = [] | |
augroup CmdComplete | |
au! | |
au CmdlineChanged : wildtrigger() | |
au CmdlineEnter : files_cache = [] | |
augroup END | |
def FindCmd(): string | |
var cmd = '' | |
if executable('fd') | |
cmd = 'fd . --path-separator / --type f --hidden --follow --exclude .git' | |
elseif executable('fdfind') | |
cmd = 'fdfind . --path-separator / --type f --hidden --follow --exclude .git' | |
elseif executable('ugrep') | |
cmd = 'ugrep "" -Rl -I --ignore-files' | |
elseif executable('rg') | |
cmd = 'rg --path-separator / --files --hidden --glob !.git' | |
elseif executable('find') | |
cmd = 'find \! \( -path "*/.git" -prune -o -name "*.swp" \) -type f -follow' | |
endif | |
return cmd | |
enddef | |
def Find(cmd_arg: string, cmd_complete: bool): list<string> | |
if empty(files_cache) | |
var cmd = FindCmd() | |
# fallback to built-in glob if no fd/rg/ug/find is available | |
# e.g. we are on Windows | |
if empty(cmd) | |
files_cache = globpath('.', '**', 1, 1) | |
->filter((_, v) => !isdirectory(v)) | |
->mapnew((_, v) => v->substitute('^\.[\/]', "", "")) | |
else | |
files_cache = systemlist(cmd) | |
endif | |
endif | |
if empty(cmd_arg) | |
return files_cache | |
else | |
return files_cache->matchfuzzy(cmd_arg) | |
endif | |
enddef | |
set findfunc=Find |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment