I'd like to automatically call the omnicompletion (that is triggered manually by <Ctrl-X><Ctrl-O>) from within a vimscript function.

I played around a bit with execute 'normal! …' and feedkeys(), but if I got it do actually do something, it always results in a literal \<C-X>\<C-O> in my document.

How can I call the omnicompletion from within a vimscript function?


What I have tried so far (to simplify the example, I just jump to line 27, enter a new line below it and start omni-completion):

execute 'normal! 27Go\<c-x>\<c-o>'
  execute 'normal! 27Go'
  execute 'normal! \<c-x>\<c-o>'
  execute 'normal! 27Go'
  call feedkeys('\<c-x>\<c-o>')

Edit 2:

Hah, thanks to @ChristianBrabant I played around a bit more and found that feedkeys() should work, but I just used it wrongly! See my own answer below: https://vi.stackexchange.com/a/21713/21417

  • so what exactly did you try? Oct 30, 2019 at 8:06
  • I just added some failed attempts
    – radlan
    Oct 30, 2019 at 10:30
  • yes, double-quoting the keys should work. Oct 30, 2019 at 11:31

1 Answer 1


feedkeys() is the correct approach, but to respect the special keys, I must use double quotes (as mentioned in the vimhelp):

  execute 'normal! 27Go'
  call feedkeys("\<c-x>\<c-o>")

Your Answer

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

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