I use omnifunc with the neovim built in LSP functionality and this is my configuration.

local lspconfig = require("lspconfig")
vim.opt.completeopt = { "longest", "menuone", "popup" }

local servers = { "rust_analyzer", "pyright", "lua_ls", "clangd" }
for _, lsp in ipairs(servers) do
    lspconfig[lsp].setup {

vim.api.nvim_create_autocmd('LspAttach', {
    group = vim.api.nvim_create_augroup('UserLspConfig', {}),
    callback = function(ev) 
        vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'

        local opts = { buffer = ev.buf }
        vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
        vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)

        vim.keymap.set("n", "<leader>i", vim.lsp.buf.implementation, opts)
        vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
        vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, opts)

        -- Hover shows information about symbol like type
        vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
        -- Diagnostics show the errors only
        vim.keymap.set("n", "<leader>D", vim.diagnostic.open_float, opts)
        vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
        vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts)

The current behavior is that after I trigger omnifunc a few times with <C-x><C-o>, it will eventually just stop working. Meaning no matter how many times I input <C-x><C-o> the menu won't appear. I need to quit neovim, and open a file again then and only then I can use omnifunc.

I uploaded a video to YouTube showing this problem. The problem shows up around 0:40.

I expect to be able to use <C-x><C-o> and the menu will show up consistently. Instead of only being able to use it a few times before I need to restart neovim.

  • If it only depends on time/tries I suppose it is either a problem in the LSP bridge or in the LSP server itself. I believe you'll have more chance to report a GitHub issues in one of these repositories. Maybe could you check if the clangd server is still running when you experience your problem. Feb 12 at 9:34
  • @VivianDeSmedt with the help of someone from the neovim IRC, they've identified the problem and gave me a solution.
    – YJH16120
    Feb 12 at 11:31
  • 1
    Great! Feel free to answer your own question. It will probably help others :-) Feb 12 at 12:20
  • I'll do that! @VivianDeSmedt was waiting for the person who helped me (seandewar) to give an explanation as to why it broke to begin with :)
    – YJH16120
    Feb 12 at 13:47

1 Answer 1


The problem is with another part of my config which runs filetype detect in an autocmd. The fix was to simply not source it.

This is the answer given by seandewar

filetype detection will set ft=c as it's a C file, which will reload the C ftplugin (which sets omnifunc to ccomplete)

This is an issue because in my config I set the value of omnifunc as something else.

vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'

So, filetype detect will set ft=c and remove the value set in my config. So, when I first open a file to edit and check the value of omnifunc this is the output.

enter image description here

Which is exactly what I set it to be. After filetype detect is ran in the autocmd the value of omnifunc changes.

enter image description here

Because the value of omnifunc changes, I am unable to use it as I want. The fix is that I should remove the filetype detect command from the autocmd.

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.