Completion with nvim-cmp

Completion with nvim-cmp

Language servers know what can complete at the cursor; a completion plugin shows it. The classic pairing is nvim-cmp with the cmp-nvim-lsp source:

Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-nvim-lsp'
local cmp = require('cmp')
cmp.setup({
  sources = { { name = 'nvim_lsp' } },
  mapping = cmp.mapping.preset.insert({
    ['<C-Space>'] = cmp.mapping.complete(),
    ['<CR>'] = cmp.mapping.confirm({ select = true }),
  }),
})

Type in a buffer with a server attached and candidates appear as you type — methods with signatures, module members, documentation alongside.

Two notes before you settle in:

  • Advertise completion capabilities to servers so they send the richer payloads (snippet support etc.) — cmp-nvim-lsp provides require('cmp_nvim_lsp').default_capabilities() for exactly that.
  • The modern config later swaps nvim-cmp for blink.cmp, a faster drop-in with the same idea. The concepts — sources, capabilities, a confirm key — transfer one to one.