From 1d9e7d2a90db238780902555d427c9e27b38b9fc Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 11 Jul 2018 13:26:49 +0900 Subject: [PATCH] Add global line completion example to README Close #622 --- README.md | 19 ++++++++++++++----- doc/fzf-vim.txt | 26 ++++++++++++++++++++------ 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 8234f9f..52283bc 100644 --- a/README.md +++ b/README.md @@ -249,13 +249,13 @@ inoremap fzf#vim#complete#word({'left': '15%'}) ### Completion helper -`fzf#complete` is a helper function for creating custom fuzzy completion using -fzf. If the first parameter is a command string or a Vim list, it will be used -as the source. +`fzf#vim#complete` is a helper function for creating custom fuzzy completion +using fzf. If the first parameter is a command string or a Vim list, it will +be used as the source. ```vim " Replace the default dictionary completion with fzf-based fuzzy completion -inoremap fzf#complete('cat /usr/share/dict/words') +inoremap fzf#vim#complete('cat /usr/share/dict/words') ``` 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 - `sink` or `sink*` are ignored +```vim +" Global line completion (not just open buffers. ripgrep required.) +inoremap 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 ```vim @@ -278,7 +287,7 @@ function! s:make_sentence(lines) return substitute(join(a:lines), '^.', '\=toupper(submatch(0))', '').'.' endfunction -inoremap fzf#complete({ +inoremap fzf#vim#complete({ \ 'source': 'cat /usr/share/dict/words', \ 'reducer': function('make_sentence'), \ 'options': '--multi --reverse --margin 15%,0', diff --git a/doc/fzf-vim.txt b/doc/fzf-vim.txt index db1a507..6bbd0e4 100644 --- a/doc/fzf-vim.txt +++ b/doc/fzf-vim.txt @@ -286,12 +286,19 @@ MAPPINGS *fzf-vim-mappings* < Completion helper >_________________________________________________________~ *fzf-vim-completion-helper* -`fzf#complete` is a helper function for creating custom fuzzy completion using -fzf. If the first parameter is a command string or a Vim list, it will be used -as the source. +`fzf#vim#complete` is a helper function for creating custom fuzzy completion +using fzf. If the first parameter is a command string or a Vim list, it will +be used as the source. > " Replace the default dictionary completion with fzf-based fuzzy completion - inoremap fzf#complete('cat /usr/share/dict/words') + inoremap fzf#vim#complete('cat /usr/share/dict/words') + + " Global line completion (ripgrep required) + inoremap 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 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 prefix as the argument and return the final value - `sink` or `sink*` are ignored - +> + " Global line completion (not just open buffers. ripgrep required.) + inoremap 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~ *fzf-vim-reducer-example* @@ -314,7 +328,7 @@ Reducer example~ return substitute(join(a:lines), '^.', '\=toupper(submatch(0))', '').'.' endfunction - inoremap fzf#complete({ + inoremap fzf#vim#complete({ \ 'source': 'cat /usr/share/dict/words', \ 'reducer': function('make_sentence'), \ 'options': '--multi --reverse --margin 15%,0',