mirror of
https://github.com/junegunn/fzf.vim.git
synced 2026-05-04 04:45:47 +08:00
Update fzf#complete to be used in expression mapping
This commit is contained in:
+32
-7
@@ -367,19 +367,44 @@ command! -bang Snippets call s:snippets(<bang>0)
|
|||||||
" ----------------------------------------------------------------------------
|
" ----------------------------------------------------------------------------
|
||||||
" Completion helper
|
" Completion helper
|
||||||
" ----------------------------------------------------------------------------
|
" ----------------------------------------------------------------------------
|
||||||
function! s:complete_insert(data)
|
inoremap <silent> <Plug>(-fzf-complete-trigger) <c-o>:call <sid>complete_trigger()<cr>
|
||||||
execute 'normal!' (empty(s:query) ? 'a' : 'ciW')."\<C-R>=a:data\<CR>"
|
|
||||||
startinsert!
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! fzf#complete(source, ...)
|
function! s:complete_trigger()
|
||||||
let s:query = get(a:, 1, expand('<cWORD>'))
|
|
||||||
call s:fzf({
|
call s:fzf({
|
||||||
\ 'source': a:source,
|
\ 'source': s:source,
|
||||||
\ 'sink': function('s:complete_insert'),
|
\ 'sink': function('s:complete_insert'),
|
||||||
\ 'options': '+m -q '.shellescape(s:query)}, 0)
|
\ 'options': '+m -q '.shellescape(s:query)}, 0)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:complete_insert(data)
|
||||||
|
let chars = strchars(s:query)
|
||||||
|
if chars == 0 | let del = ''
|
||||||
|
elseif chars == 1 | let del = '"_x'
|
||||||
|
else | let del = (chars - 1).'"_dvh'
|
||||||
|
endif
|
||||||
|
execute 'normal!' (s:eol ? '' : 'h').del.(s:eol ? 'a': 'i').a:data
|
||||||
|
if has('nvim')
|
||||||
|
call feedkeys('a')
|
||||||
|
else
|
||||||
|
execute "normal! \<esc>la"
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! fzf#complete(source)
|
||||||
|
let s:source = a:source
|
||||||
|
|
||||||
|
let eol = col('$')
|
||||||
|
let ve = &ve
|
||||||
|
set ve=all
|
||||||
|
let s:eol = col('.') == eol
|
||||||
|
let &ve = ve
|
||||||
|
|
||||||
|
let s:query = col('.') == 1 ? '' :
|
||||||
|
\ matchstr(getline('.')[0 : col('.')-2], '\k*$')
|
||||||
|
call feedkeys("\<Plug>(-fzf-complete-trigger)")
|
||||||
|
return ''
|
||||||
|
endfunction
|
||||||
|
|
||||||
" ------------------------------------------------------------------
|
" ------------------------------------------------------------------
|
||||||
let &cpo = s:cpo_save
|
let &cpo = s:cpo_save
|
||||||
unlet s:cpo_save
|
unlet s:cpo_save
|
||||||
|
|||||||
Reference in New Issue
Block a user