Browse code

Update README.md

John Hawthorn authored on 04/08/2014 21:47:40
Showing 3 changed files

... ...
@@ -1,7 +1,7 @@
1 1
 VERSION=0.1beta
2 2
 
3 3
 CPPFLAGS=-DVERSION=\"${VERSION}\"
4
-CFLAGS+=-Wall -Wextra -g -std=c99
4
+CFLAGS+=-Wall -Wextra -g -std=c99 -O2
5 5
 PREFIX?=/usr/local
6 6
 
7 7
 INSTALL=install
... ...
@@ -1,9 +1,8 @@
1 1
 # fzy
2 2
 
3 3
 A fuzzy text selector for terminals in C inspired by
4
-[selecta](https://github.com/garybernhardt/selecta)
5
-and
6
-[dmenu](http://tools.suckless.org/dmenu/)
4
+[selecta](https://github.com/garybernhardt/selecta),
5
+but with an improved [scoring algorithm](#sorting).
7 6
 
8 7
 ![](http://i.hawth.ca/u/fzy2.gif)
9 8
 
... ...
@@ -14,3 +13,46 @@ and
14 13
 
15 14
 The `PREFIX` environment variable can be used to specify the install location,
16 15
 the default is `/usr/local`.
16
+
17
+## Usage
18
+
19
+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).
20
+
21
+### Use with Vim
22
+
23
+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.
24
+
25
+``` vim
26
+function! FzyCommand(choice_command, vim_command)
27
+  silent let output = system(a:choice_command . " | fzy ")
28
+  redraw!
29
+  if v:shell_error == 0 && !empty(output)
30
+    exec a:vim_command . ' ' . output
31
+  endif
32
+endfunction
33
+
34
+nnoremap <leader>e :call FzyCommand("find -type f", ":e")<cr>
35
+nnoremap <leader>v :call FzyCommand("find -type f", ":vs")<cr>
36
+nnoremap <leader>s :call FzyCommand("find -type f", ":sp")<cr>
37
+```
38
+
39
+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`.
40
+
41
+``` vim
42
+nnoremap <leader>e :call FzyCommand("ag . --no-color -l -g ''", ":e")<cr>
43
+nnoremap <leader>v :call FzyCommand("ag . --no-color -l -g ''", ":vs")<cr>
44
+nnoremap <leader>s :call FzyCommand("ag . --no-color -l -g ''", ":sp")<cr>
45
+```
46
+
47
+## Sorting
48
+
49
+fzy attempts to present the best matches first. The following considerations are weighted when sorting:
50
+
51
+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>.
52
+
53
+It prefers consecutive characters: `file` will match <tt><b>file</b></tt> over <tt><b>fil</b>t<b>e</b>r</tt>.
54
+
55
+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>.
56
+
57
+It prefers shorter candidates: `test` matches <tt><b>test</b>s</tt> over <tt><b>test</b>ing</b></tt>.
58
+
... ...
@@ -42,6 +42,9 @@ int test_scoring(){
42 42
 	assert(match("gemfil", "Gemfile.lock") < match("gemfil", "Gemfile"));
43 43
 
44 44
 	/* Prefer shorter matches */
45
+	assert(match("abce", "abcdef") > match("abce", "abc de"));
46
+
47
+	/* Prefer shorter candidates */
45 48
 	assert(match("test", "tests") > match("test", "testing"));
46 49
 
47 50
 	/* Scores first letter highly */