1

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?

Edit:

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'
  startinsert
  execute 'normal! \<c-x>\<c-o>'
  execute 'normal! 27Go'
  startinsert
  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? – Christian Brabandt Oct 30 at 8:06
  • I just added some failed attempts – radlan Oct 30 at 10:30
  • yes, double-quoting the keys should work. – Christian Brabandt Oct 30 at 11:31
2

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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