diff --git a/lua/core.lua b/lua/core.lua index ef3a5af..010a15e 100644 --- a/lua/core.lua +++ b/lua/core.lua @@ -11,7 +11,7 @@ o.showmode = false o.scrolloff = 10 -- controlling -vim.opt.completeopt = { 'menu', 'menuone', 'noselect' } +vim.opt.completeopt = { 'menu', 'menuone', 'noinsert' } o.ignorecase = true o.smartcase = true o.smartindent = true diff --git a/lua/lazy-plugins.lua b/lua/lazy-plugins.lua index 7bf35c3..edb5ac0 100644 --- a/lua/lazy-plugins.lua +++ b/lua/lazy-plugins.lua @@ -36,11 +36,13 @@ local plugins = { }, -- TS, LSP, Completion { - "williamboman/mason.nvim" + "williamboman/mason.nvim", + lazy = true }, { "nvim-treesitter/nvim-treesitter", + lazy = true, config = function() require("plugins.treesitter") end @@ -51,14 +53,18 @@ local plugins = { "nvim-treesitter/nvim-treesitter", }, }, + { + "L3MON4D3/LuaSnip", + dependencies = { "rafamadriz/friendly-snippets" }, + lazy = true + }, { "hrsh7th/nvim-cmp", dependencies = { - { - "hrsh7th/cmp-nvim-lsp", - }, + "hrsh7th/cmp-nvim-lsp", -- TODO: check the cmp sources "hrsh7th/cmp-buffer", + "hrsh7th/cmp-nvim-lua", "hrsh7th/cmp-cmdline", "FelipeLema/cmp-async-path", "ray-x/cmp-treesitter", diff --git a/lua/plugins/cmp.lua b/lua/plugins/cmp.lua index 5070181..1d35d37 100644 --- a/lua/plugins/cmp.lua +++ b/lua/plugins/cmp.lua @@ -9,6 +9,7 @@ end local luasnip = require("luasnip") local cmp = require("cmp") + cmp.setup({ -- ... Your other configuration ... snippet = { @@ -23,9 +24,7 @@ cmp.setup({ mapping = { [""] = cmp.mapping(function(fallback) if cmp.visible() then - cmp.select_next_item() - -- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable() - -- they way you will only jump inside the snippet region + cmp.confirm({ select = true }) elseif luasnip.expand_or_jumpable() then luasnip.expand_or_jump() elseif has_words_before() then @@ -45,6 +44,8 @@ cmp.setup({ end, { "i", "s" }), [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.select_prev_item(), [''] = cmp.mapping.complete(), [''] = cmp.mapping.abort(), [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items @@ -53,12 +54,15 @@ cmp.setup({ sources = cmp.config.sources({ { name = "luasnip" }, -- For luasnip users. { name = "nvim_lsp" }, + { name = 'nvim_lua' }, { name = "treesitter" }, { name = "async_path" }, { name = "git" }, { name = "buffer" }, - }) - -- ... Your other configuration ... + }), + completion = { + completeopt = 'menu,menuone,noinsert' + } }) cmp.setup.cmdline({ '/', '?' }, { diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index 1f200c1..d6a196e 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -20,7 +20,7 @@ vim.api.nvim_create_autocmd('LspAttach', { vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) - vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts) + vim.keymap.set({'n', 'i'}, '', vim.lsp.buf.signature_help, opts) vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, opts) vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, opts) vim.keymap.set('n', 'wl', function() diff --git a/lua/plugins/nvim-autopairs.lua b/lua/plugins/nvim-autopairs.lua index d3493dd..ed548af 100644 --- a/lua/plugins/nvim-autopairs.lua +++ b/lua/plugins/nvim-autopairs.lua @@ -7,8 +7,3 @@ npairs.setup({ enable_check_bracket_line = true, check_ts = true, }) - --- If you want insert `(` after select function or method item -local cmp_autopairs = require("nvim-autopairs.completion.cmp") -local cmp = require("cmp") -cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done())