-- completeopt is used to manage code suggestions -- menuone: show popup even when there is only one suggestion -- noinsert: Only insert text when selection is confirmed -- noselect: force us to select one from the suggestions vim.opt.completeopt = {'menuone', 'noselect', 'noinsert', 'preview'} -- shortmess is used to avoid excessive messages vim.opt.shortmess = vim.opt.shortmess + { c = true} local cmp = require'cmp' cmp.setup({ snippet = { expand = function(args) require('luasnip').lsp_expand(args.body) -- For `luasnip` users. end, }, mapping = { -- Shift+TAB to go to the Previous Suggested item [''] = cmp.mapping.select_prev_item(), -- Tab to go to the next suggestion [''] = cmp.mapping.select_next_item(), -- CTRL+SHIFT+f to scroll backwards in description [''] = cmp.mapping.scroll_docs(-4), -- CTRL+F to scroll forwards in the description [''] = cmp.mapping.scroll_docs(4), -- CTRL+SPACE to bring up completion at current Cursor location [''] = cmp.mapping.complete(), -- CTRL+e to exit suggestion and close it [''] = cmp.mapping.close(), -- CR (enter or return) to CONFIRM the currently selection suggestion -- We set the ConfirmBehavior to insert the Selected suggestion [''] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = true, }) }, -- sources are the installed sources that can be used for code suggestions sources = { { name = 'path' }, { name = 'nvim_lsp', keyword_length = 3 }, { name = 'nvim_lsp_signature_help'}, { name = 'nvim_lua', keyword_length = 2}, { name = 'buffer', keyword_length = 2 }, { name = 'vsnip', keyword_length = 2 }, } })