Search code examples
luaneovimneovim-pluginnvim-lspconfignvim.cmp

How to trigger lsp suggestion popup in neovim?


I'm using nvchad neovim setup with typescript lsp. Lsp works just fine and opens me list with suggestions to autocomplete, but only when I start typing something. What I want to be able to do is to trigger this suggestions list to pop up by pressing some hotkey

There is how it looks like

No typing

Started typing

I don't know if it useful, but I use next plugins for lsp:

  • nvim-lspconfig
  • mason.nvim
  • mason-lspconfig.nvim

Also nvchad configuration has auto setup for nvim-cmp and LuaSnip plugins. I didn't configure them manually


Solution

  • In NvChad, autocompletion is <C-Space> (Control + Space) by default

    nvim-cmp is responsible for autocompletion.

    If you want to change the default mapping, you have to add custom plugin options in NvChad (source):

    • custom/chadrc.lua
    M.plugins = "custom.plugins"
    
    • custom/plugins.lua
    local plugins = {
      -- this opts will extend the default opts 
      {
        "hrsh7th/nvim-cmp",
        opts = {
          mapping = {
            ["<C-Space>"] = cmp.mapping.complete(), -- Replace with whatever you want
          },
        },
      },
    }
    
    return plugins
    

    NOTE: This is true only to NvChad. For configuring with any other neovim config, consult the documentation.

    I recommend creating your own config instead of using a ready-made distribution like NvChad. It gives you a deep understanding of neovim configuration. If you don't know where to start, check out kickstart.nvim