Ctrl-x Ctrl-o behaviour with omnifunc

First, let me thank all the Neovim & neovim-lsp maintainers for the wonderful piece of software, it helps me every single day to get the job done!

Now onto the problem: I am working mainly on OCaml code and use merlin (GitHub - ocaml/merlin: Context sensitive completion for OCaml in Vim and Emacs) for completion/diagnostics. Recently, I decided to try builtin lsp with ocamllsp (which uses merlin as a backend btw). So far, looks really good! There is one piece of it, which I don’t really understand - omnicompletion behaviour with <ctrl-x> <ctrl-o>. Typically, I press <ctrl-x> and then <ctrl-o> multiple times. This selects & pre-fills each new alternative until I am satisfied. See recording:
merlin

I wanted to do the same with lsp version and have this in my lua heredoc string

  local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
  buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')

But it doesn’t behave as I expect. Specifically, the completion menu gets populated on <ctrl-x><ctrl-o>, but the next <ctrl-o> closes the completion menu and leaves me with the initial prefix / diagnostic message. Like this:

Will attach the recording to the first comment because of limitations for new users

The question is - is it a bug or feature? If the latter - what is the way to make it work like merlin does?
FTR, merlin does this for omnifunc: merlin/merlin.vim at master · ocaml/merlin · GitHub

This is how lsp behaves:
lsp

I unfortunately can’t reproduce this with Merlin. Does :verbose map <c-o> show any unexpected output?

You can use <C-n> and <C-p> to nevigate up and down in popup menu . You could probably create a keymap like following to achive what you’re looking for

inoremap <silent><expr> <C-o> pumvisible() ? "\<C-n>" : "\<C-o>"
1 Like

Thank you so much! That did the trick!

Both :verbose map <c-o> and :verbose imap <c-o> show No mapping found. The solution proposed by @shadman does the job though. Not sure what is different for merlin :man_shrugging: