hrsh7th / cmp-nvim-lsp

nvim-cmp source for neovim builtin LSP client
MIT License
1.31k stars 52 forks source link

How to cycle through autocompletion options? #31

Open CCLDArjun opened 2 years ago

CCLDArjun commented 2 years ago

I have this config:

require'cmp'.setup {
  sources = {
    { name = 'nvim_lsp' }
  }
}

local custom_attach = function(client, bufnr)
 -- this code gets executed when a language server is attached to a buffer
 -- you can add your keybindings and commands here.
end

-- The nvim-cmp almost supports LSP's capabilities so You should advertise it to LSP servers..
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)

local capabilities = require('cmp_nvim_lsp').update_capabilities(
  vim.lsp.protocol.make_client_capabilities()
)

vim.cmd [[packadd packer.nvim]]
require('packer').startup(function(use)
    use 'wbthomason/packer.nvim'
    use 'neovim/nvim-lspconfig'
end)

require'lspconfig'.pyright.setup {
  on_attach = custom_attach,
  capabilities = capabilities
}

require'lspconfig'.pyright.setup {
  on_attach = custom_attach,
  capabilities = capabilities
}
require'lspconfig'.rust_analyzer.setup {
  on_attach = custom_attach,
  capabilities = capabilities
}

it's using lspconfig. I can see the lsp autocompletion options but I'm not able to cycle through or select them. Hitting tab inserts a space character and ctrl-n or ctrl-p opens the vim autocomplete.

ghost commented 2 years ago

Hey mate, if you follow the example mappings that are provided in the nvim-cmp wiki, you should be able to find the key mappings that you need! Here's a link:

https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings#luasnip

Keep in mind that the keybindings are specific to the snippet engine that you're using.