diff --git a/lua/plugins/code.lua b/lua/plugins/code.lua index 96297c3..f81c8ad 100644 --- a/lua/plugins/code.lua +++ b/lua/plugins/code.lua @@ -49,18 +49,20 @@ return { }, { "hrsh7th/nvim-cmp", - event = "InsertEnter", + event = { "InsertEnter", "CmdlineEnter", }, dependencies = { -- Snippet engine "L3MON4D3/LuaSnip", "saadparwaiz1/cmp_luasnip", - -- Plugins "hrsh7th/cmp-buffer", -- indexer "hrsh7th/cmp-path", -- Autocomplete for filesystem paths "hrsh7th/cmp-cmdline", -- Autocomplete for vims commandline "hrsh7th/cmp-nvim-lua", -- Autocomplete for vim options + + -- Looks + "onsails/lspkind.nvim", -- Add symbols for type }, config = function() local cmp = require("cmp") @@ -71,12 +73,63 @@ return { require("luasnip").lsp_expand(args.body) end }, + view = { + entries = { + name = 'custom', + selection_order = 'near_cursor' + } + }, + formatting = { + format = require("lspkind").cmp_format({ + mode = "symbol_text", + maxwidth = 50, + ellipsis_char = "...", + show_labelDetails = true, + }), + }, sources = { { name = "nvim_lsp" }, { name = "luasnip" }, { name = "buffer" }, { name = "path" }, }, + mapping = { + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + if #cmp.get_entries() == 1 then + cmp.confirm({ select = true }) + else + cmp.select_next_item() + end + --[[ Replace with your snippet engine (see above sections on this page) + elseif snippy.can_expand_or_advance() then + snippy.expand_or_advance() + elseif has_words_before() then + cmp.complete() + if #cmp.get_entries() == 1 then + cmp.confirm({ select = true }) + end]] + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + end + end, { "i", "s", "c" }), + [""] = cmp.mapping({ + i = function(fallback) + if cmp.visible() and cmp.get_active_entry() then + cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false }) + else + fallback() + end + end, + s = cmp.mapping.confirm({ select = true }), + c = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace }), + }), + }, enabled = function() local context = require("cmp.config.context") -- disable in autocomplete in comments @@ -101,5 +154,7 @@ return { matching = { disallow_symbol_nonprefix_matching = false } }) end + }, + { } }