diff options
author | John Hawthorn <john.hawthorn@gmail.com> | 2014-08-04 14:47:40 -0700 |
---|---|---|
committer | John Hawthorn <john.hawthorn@gmail.com> | 2014-08-04 17:59:44 -0700 |
commit | 175ffa6dc4f6ddad71ca1ddf7dc9a9007c4c6348 (patch) | |
tree | e9bdd14fe2127d70632b9ae13b774e6f1ac72713 | |
parent | b18b7a0701474b41a760931cf840f922607851d9 (diff) |
Update README.md
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | README.md | 48 | ||||
-rw-r--r-- | fzytest.c | 3 |
3 files changed, 49 insertions, 4 deletions
@@ -1,7 +1,7 @@ VERSION=0.1beta CPPFLAGS=-DVERSION=\"${VERSION}\" -CFLAGS+=-Wall -Wextra -g -std=c99 +CFLAGS+=-Wall -Wextra -g -std=c99 -O2 PREFIX?=/usr/local INSTALL=install @@ -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 <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)](https://github.com/ggreer/the_silver_searcher) can be used to ignore files specified by `.gitignore`. + +``` vim +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> +``` + +## 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 <tt><b>a</b>pp/<b>m</b>odels/<b>o</b>rder.rb</tt>. + +It prefers consecutive characters: `file` will match <tt><b>file</b></tt> over <tt><b>fil</b>t<b>e</b>r</tt>. + +It prefers shorter matches: `abce` matches <tt><b>abc</b>d<b>e</b>f</tt> over <tt><b>abc</b> d<b>e</b></tt>. + +It prefers shorter candidates: `test` matches <tt><b>test</b>s</tt> over <tt><b>test</b>ing</b></tt>. + @@ -42,6 +42,9 @@ int test_scoring(){ assert(match("gemfil", "Gemfile.lock") < match("gemfil", "Gemfile")); /* Prefer shorter matches */ + assert(match("abce", "abcdef") > match("abce", "abc de")); + + /* Prefer shorter candidates */ assert(match("test", "tests") > match("test", "testing")); /* Scores first letter highly */ |