A fuzzy text selector for terminals in C inspired by selecta, but with an improved scoring algorithm.
It's been kind of life-changing. -@graygilmore
fzy works great btw -@alexblackie
$ make
$ sudo make install
The PREFIX
environment variable can be used to specify the install location,
the default is /usr/local
.
fzy is a drop in replacement for selecta, and can be used with its usage examples.
fzy can be integrated very simply in vim. There is also fzy-vim, a more fully featured vim plugin.
function! FzyCommand(choice_command, vim_command)
try
let output = system(a:choice_command . " | fzy ")
catch /Vim:Interrupt/
" Swallow errors from ^C, allow redraw! below
endtry
redraw!
if v:shell_error == 0 && !empty(output)
exec a:vim_command . ' ' . output
endif
endfunction
nnoremap <leader>e :call FzyCommand("find -type f", ":e")<cr>
nnoremap <leader>v :call FzyCommand("find -type f", ":vs")<cr>
nnoremap <leader>s :call FzyCommand("find -type f", ":sp")<cr>
Any program can be used to filter files presented through fzy. ag (the silver searcher) can be used to ignore files specified by .gitignore
.
nnoremap <leader>e :call FzyCommand("ag . --no-color -l -g ''", ":e")<cr>
nnoremap <leader>v :call FzyCommand("ag . --no-color -l -g ''", ":vs")<cr>
nnoremap <leader>s :call FzyCommand("ag . --no-color -l -g ''", ":sp")<cr>
fzy attempts to present the best matches first. The following considerations are weighted when sorting:
It prefers consecutive characters: file
will match file over filter.
It prefers matching the beginning of words: amp
is likely to match app/models/posts.rb.
It prefers shorter matches: abce
matches abcdef over abc de.
It prefers shorter candidates: test
matches tests over testing.