I saw this post on Stack Overflow asking the same question but the response simply was "Don’t use feedkeys, here is a different solution." Well I have a use case where I think I do need feedkeys. Here is my function:

function! OpenCompletion()
    if !pumvisible()
        if (v:char == '/' || v:char == '$' || v:char == '~' || v:char == '.')
            call feedkeys("\<c-x>\<c-f>")
        elseif ((v:char >= 'a' && v:char <= 'z') || (v:char >= 'A' && v:char <= 'Z') || (v:char >= '0' || v:char == '0'))
            call feedkeys("\<plug>vim_completes_me_forward")

autocmd insertcharpre * call OpenCompletion()

I want it to run the commands silently so that it doesn't show any messages at the bottom. Also, apparently this is impossible with feedkeys(). So I am trying to do it with getcompletion().

  • 1
    please explain, what you mean with silently. What exactly do you want to hide? Commented Aug 12, 2022 at 6:21
  • I want to hide the messages that appear on the bottom of the window.
    – Amarakon
    Commented Aug 12, 2022 at 17:18
  • You can't really do that; feedkeys() is as-if you typed the keys yourself, in your case <C-x><C-f>. You can use something like getcompletion('<cword>', 'file'), maybe in combination with complete(), but it's not entirely clear what you want to do. But basically: if you don't want things to behave exactly like it would like you're using it from insert mode, then feedkeys() is the wrong choice. Commented Aug 12, 2022 at 17:49
  • I understand. How can I create a menu of the results getcompletion()? For example: echo getcompletion('call ', 'cmdline') will print to the screen but I want it in a popup menu instead. It is not clear from the documentation how to do this.
    – Amarakon
    Commented Aug 12, 2022 at 20:23
  • Something like complete(col('.'), getcompletion('<cword>', 'file')) I think, but I never used these functions before either so not 100% sure 😅 It would probably be best if you would edit your answer to better describe what behaviour/goal you're looking for, because now that's a bit unclear to me, so hard to tell what the best option is. Also, you seem to be using VimCompletesMe, and maybe that already has a feature for this. Commented Aug 12, 2022 at 21:35


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.