From 175ffa6dc4f6ddad71ca1ddf7dc9a9007c4c6348 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Mon, 4 Aug 2014 14:47:40 -0700 Subject: Update README.md --- README.md | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index e4dcf2e..32b1f7a 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,8 @@ # fzy A fuzzy text selector for terminals in C inspired by -[selecta](https://github.com/garybernhardt/selecta) -and -[dmenu](http://tools.suckless.org/dmenu/) +[selecta](https://github.com/garybernhardt/selecta), +but with an improved [scoring algorithm](#sorting). ![](http://i.hawth.ca/u/fzy2.gif) @@ -14,3 +13,46 @@ and The `PREFIX` environment variable can be used to specify the install location, the default is `/usr/local`. + +## Usage + +fzy is a drop in replacement for [selecta](https://github.com/garybernhardt/selecta), and can be used with its [usage examples](https://github.com/garybernhardt/selecta#usage-examples). + +### Use with Vim + +fzy can be integrated very simply in vim. There is also [fzy-vim](https://github.com/Dkendal/fzy-vim), a more fully featured vim plugin. + +``` vim +function! FzyCommand(choice_command, vim_command) + silent let output = system(a:choice_command . " | fzy ") + redraw! + if v:shell_error == 0 && !empty(output) + exec a:vim_command . ' ' . output + endif +endfunction + +nnoremap e :call FzyCommand("find -type f", ":e") +nnoremap v :call FzyCommand("find -type f", ":vs") +nnoremap s :call FzyCommand("find -type f", ":sp") +``` + +Any program can be used to filter files presented through fzy. [ag (the silver searcher)](https://github.com/ggreer/the_silver_searcher) can be used to ignore files specified by `.gitignore`. + +``` vim +nnoremap e :call FzyCommand("ag . --no-color -l -g ''", ":e") +nnoremap v :call FzyCommand("ag . --no-color -l -g ''", ":vs") +nnoremap s :call FzyCommand("ag . --no-color -l -g ''", ":sp") +``` + +## Sorting + +fzy attempts to present the best matches first. The following considerations are weighted when sorting: + +It prefers matching the beginning of words: `amo` is likely to match app/models/order.rb. + +It prefers consecutive characters: `file` will match file over filter. + +It prefers shorter matches: `abce` matches abcdef over abc de. + +It prefers shorter candidates: `test` matches tests over testing. + -- cgit v1.2.3