diff --git a/lua/config/lazy.lua b/lua/config/lazy.lua index a754fb0..1f03726 100644 --- a/lua/config/lazy.lua +++ b/lua/config/lazy.lua @@ -5,6 +5,26 @@ require("lazy").setup({ { "hrsh7th/nvim-cmp", dependencies = { + -- Code snippet engine + { + "L3MON4D3/LuaSnip", + version = "v2.*", + }, + { + "windwp/nvim-autopairs", + opts = { + fast_wrap = {}, + disable_filetype = { "TelescopePrompt", "vim" }, + }, + config = function(_, opts) + require("nvim-autopairs").setup(opts) + + -- setup cmp for autopairs + local cmp_autopairs = require "nvim-autopairs.completion.cmp" + require("cmp").event:on("confirm_done", cmp_autopairs.on_confirm_done()) + end, + }, + "hrsh7th/cmp-nvim-lsp", -- lsp auto-completion "hrsh7th/cmp-buffer", -- buffer auto-completion "hrsh7th/cmp-path", -- path auto-completion @@ -14,12 +34,6 @@ require("lazy").setup({ require("config.nvim-cmp") end, }, - -- Code snippet engine - { - "L3MON4D3/LuaSnip", - version = "v2.*", - }, - -- LSP manager "williamboman/mason.nvim", "williamboman/mason-lspconfig.nvim", diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index b58a092..54a03ec 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -65,6 +65,8 @@ local on_attach = function(client, bufnr) --end, bufopts) end +local capabilities = require("cmp_nvim_lsp").default_capabilities() + -- Configure each language -- How to add LSP for a specific language? -- 1. use `:Mason` to install corresponding LSP @@ -73,5 +75,6 @@ end for _, lsp in ipairs(servers) do lspconfig[lsp].setup { on_attach = on_attach, + capabilities = capabilities, } end diff --git a/lua/config/nvim-cmp.lua b/lua/config/nvim-cmp.lua index 9e8ea20..960e5a8 100644 --- a/lua/config/nvim-cmp.lua +++ b/lua/config/nvim-cmp.lua @@ -7,6 +7,9 @@ end local luasnip = require("luasnip") local cmp = require("cmp") +vim.keymap.set({ "i", "s" }, "", function() luasnip.jump(1) end, { silent = true }) +vim.keymap.set({ "i", "s" }, "", function() luasnip.jump(-1) end, { silent = true }) + cmp.setup({ snippet = { -- REQUIRED - you must specify a snippet engine @@ -76,4 +79,5 @@ cmp.setup({ { name = 'buffer' }, -- For buffer word completion { name = 'path' }, -- For path completion }) + }) diff --git a/readme.md b/readme.md index 2d6c504..57f0fe6 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ # TODO: - [x] commenting in normal / visual mode with '/' -- [ ] autoclosing of brackets +- [x] autoclosing of brackets - [ ] type information in complete function