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