Add global line completion example to README

Close #622
This commit is contained in:
Junegunn Choi
2018-07-11 13:26:49 +09:00
parent 033033daa3
commit 1d9e7d2a90
2 changed files with 34 additions and 11 deletions

View File

@@ -249,13 +249,13 @@ inoremap <expr> <c-x><c-k> fzf#vim#complete#word({'left': '15%'})
### Completion helper ### Completion helper
`fzf#complete` is a helper function for creating custom fuzzy completion using `fzf#vim#complete` is a helper function for creating custom fuzzy completion
fzf. If the first parameter is a command string or a Vim list, it will be used using fzf. If the first parameter is a command string or a Vim list, it will
as the source. be used as the source.
```vim ```vim
" Replace the default dictionary completion with fzf-based fuzzy completion " Replace the default dictionary completion with fzf-based fuzzy completion
inoremap <expr> <c-x><c-k> fzf#complete('cat /usr/share/dict/words') inoremap <expr> <c-x><c-k> fzf#vim#complete('cat /usr/share/dict/words')
``` ```
For advanced uses, you can pass an options dictionary to the function. The set For advanced uses, you can pass an options dictionary to the function. The set
@@ -271,6 +271,15 @@ following exceptions:
completion prefix as the argument and return the final value completion prefix as the argument and return the final value
- `sink` or `sink*` are ignored - `sink` or `sink*` are ignored
```vim
" Global line completion (not just open buffers. ripgrep required.)
inoremap <expr> <c-x><c-l> fzf#vim#complete(fzf#wrap({
\ 'prefix': '^.*$',
\ 'source': 'rg -n ^ --color always',
\ 'options': '--ansi --delimiter : --nth 3..',
\ 'reducer': { lines -> join(split(lines[0], ':\zs')[2:], '') }}))
```
#### Reducer example #### Reducer example
```vim ```vim
@@ -278,7 +287,7 @@ function! s:make_sentence(lines)
return substitute(join(a:lines), '^.', '\=toupper(submatch(0))', '').'.' return substitute(join(a:lines), '^.', '\=toupper(submatch(0))', '').'.'
endfunction endfunction
inoremap <expr> <c-x><c-s> fzf#complete({ inoremap <expr> <c-x><c-s> fzf#vim#complete({
\ 'source': 'cat /usr/share/dict/words', \ 'source': 'cat /usr/share/dict/words',
\ 'reducer': function('<sid>make_sentence'), \ 'reducer': function('<sid>make_sentence'),
\ 'options': '--multi --reverse --margin 15%,0', \ 'options': '--multi --reverse --margin 15%,0',

View File

@@ -286,12 +286,19 @@ MAPPINGS *fzf-vim-mappings*
< Completion helper >_________________________________________________________~ < Completion helper >_________________________________________________________~
*fzf-vim-completion-helper* *fzf-vim-completion-helper*
`fzf#complete` is a helper function for creating custom fuzzy completion using `fzf#vim#complete` is a helper function for creating custom fuzzy completion
fzf. If the first parameter is a command string or a Vim list, it will be used using fzf. If the first parameter is a command string or a Vim list, it will
as the source. be used as the source.
> >
" Replace the default dictionary completion with fzf-based fuzzy completion " Replace the default dictionary completion with fzf-based fuzzy completion
inoremap <expr> <c-x><c-k> fzf#complete('cat /usr/share/dict/words') inoremap <expr> <c-x><c-k> fzf#vim#complete('cat /usr/share/dict/words')
" Global line completion (ripgrep required)
inoremap <expr> <c-x><c-l> fzf#vim#complete(fzf#wrap({
\ 'prefix': '^.*$',
\ 'source': 'rg -n ^ --color always',
\ 'options': '--ansi --delimiter : --nth 3..',
\ 'reducer': { lines -> join(split(lines[0], ':\zs')[2:], '') }}))
< <
For advanced uses, you can pass an options dictionary to the function. The set For advanced uses, you can pass an options dictionary to the function. The set
of options is pretty much identical to that for `fzf#run` only with the of options is pretty much identical to that for `fzf#run` only with the
@@ -305,7 +312,14 @@ following exceptions:
- Both `source` and `options` can be given as funcrefs that take the completion - Both `source` and `options` can be given as funcrefs that take the completion
prefix as the argument and return the final value prefix as the argument and return the final value
- `sink` or `sink*` are ignored - `sink` or `sink*` are ignored
>
" Global line completion (not just open buffers. ripgrep required.)
inoremap <expr> <c-x><c-l> fzf#vim#complete(fzf#wrap({
\ 'prefix': '^.*$',
\ 'source': 'rg -n ^ --color always',
\ 'options': '--ansi --delimiter : --nth 3..',
\ 'reducer': { lines -> join(split(lines[0], ':\zs')[2:], '') }}))
<
Reducer example~ Reducer example~
*fzf-vim-reducer-example* *fzf-vim-reducer-example*
@@ -314,7 +328,7 @@ Reducer example~
return substitute(join(a:lines), '^.', '\=toupper(submatch(0))', '').'.' return substitute(join(a:lines), '^.', '\=toupper(submatch(0))', '').'.'
endfunction endfunction
inoremap <expr> <c-x><c-s> fzf#complete({ inoremap <expr> <c-x><c-s> fzf#vim#complete({
\ 'source': 'cat /usr/share/dict/words', \ 'source': 'cat /usr/share/dict/words',
\ 'reducer': function('<sid>make_sentence'), \ 'reducer': function('<sid>make_sentence'),
\ 'options': '--multi --reverse --margin 15%,0', \ 'options': '--multi --reverse --margin 15%,0',