mirror of
https://github.com/junegunn/fzf.vim.git
synced 2025-12-06 12:44:24 +08:00
19
README.md
19
README.md
@@ -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',
|
||||||
|
|||||||
@@ -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',
|
||||||
|
|||||||
Reference in New Issue
Block a user