0

I'm not really sure how to describe this behavior better than with the example I'm dealing with.

I'm trying to write a custom completion using fzf-vim ... and as I'm looking through the documentation, there is a section that describes how to do it briefly, but since I don't understand it fully, I wanted to play with the API.

So naturally I thought I'd be able to just do

:call fzf#vim#complete('cat /usr/share/dict/words')

instead of binding it to a binding and using that binding like they show with

inoremap <expr> <c-x><c-k> fzf#vim#complete('cat /usr/share/dict/words')

but the problem is, while the binding does pop up fzf, the :call fzf#vim#complete(...) seems to do nothing.

I'm not sure what is causing this behavior, and if there is some other way I should be invoking the function? I don't mind reading stuff up in the documentation and learning about vimscript, but at this point I really don't know where to look anymore


As a side note, what I'm actually trying to do is create a fzf wrapper around :digraph. I wasn't sure if this would be possible with just the output of :digraph, so I found unicode.vim which even provides a function FindUnicodeBy which seems I should be able to just pass into the fzf#vim#complete wrapper, but I can't even figure out how to test the completion function.

Any tips are very welcome, as well as references to stuff to read to be able to work better with vimscript!

  • For reading references, the help, vimruntime, and Steve Losh’s « Learn vimscript the hard way » are good starts. – D. Ben Knoble Dec 11 '18 at 18:09
  • 3
    Jacub, try :echo fzf#vim#complete('cat /usr/share/dict/words'). See :help :map-expression. – Ralf Dec 11 '18 at 19:18
1

This touches the implementation details of fzf#complete. If you look into the source code of fzf#vim#complete, you will see

call feedkeys("\<Plug>(-fzf-complete-trigger)")
return ''

So when you do imap <expr> xxxx fzf#vim#complete(), what returns from the expression is '', and the key \<Plug>(-fzf-complete-trigger) stored in a buffer and is to be processed later. This key is actually defined by

imap <Plug>(-fzf-complete-trigger) <c-o>:call s:_complete_trigger()<cr>

There is no nmap defined for it. So you won't get anything if you do

:call fzf#vim#complete('cat /usr/share/dict/words')

I actually didn't get your purpose to run it in normal mode. But if just want to have this ability, you can do

nmap <expr> xxx 'i' . fzf#vim#complete('cat /usr/share/dict/words')

or (this method adds key i before \<Plug>(-fzf-complete-trigger)

:call feedkeys("i") | call fzf#vim#complete('cat /usr/share/dict/words')

or to modify fzf source code to expose s:_complete_trigger as a global function and call that function.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.