From cc505b67594fe82a034fcfdc0f8a8afa8d4e397e Mon Sep 17 00:00:00 2001 From: Vincent Capelle Date: Sun, 17 Nov 2024 02:05:22 -0500 Subject: [PATCH] feat: add autocompletion Neovim configuration --- vim/lazy-lock.json | 5 +++ vim/lua/plugins/completion.lua | 76 ++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 vim/lua/plugins/completion.lua diff --git a/vim/lazy-lock.json b/vim/lazy-lock.json index 1bdc9d1..ab4cb58 100644 --- a/vim/lazy-lock.json +++ b/vim/lazy-lock.json @@ -1,6 +1,10 @@ { + "LuaSnip": { "branch": "master", "commit": "03c8e67eb7293c404845b3982db895d59c0d1538" }, "bullets.vim": { "branch": "master", "commit": "83fa7298085be647e6b378ef2c8ca491ca032154" }, + "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, "cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, "conform.nvim": { "branch": "master", "commit": "6239d9986f51ca93ded99ecdb1af0e287eabb651" }, "csv.vim": { "branch": "master", "commit": "bddfcbadd788ab11eb3dbba4550a38a412fe3705" }, "dressing.nvim": { "branch": "master", "commit": "43b8f74e0b1e3f41e51f640f8efa3bcd401cea0d" }, @@ -14,6 +18,7 @@ "mason-tool-installer.nvim": { "branch": "main", "commit": "c5e07b8ff54187716334d585db34282e46fa2932" }, "mason.nvim": { "branch": "main", "commit": "c43eeb5614a09dc17c03a7fb49de2e05de203924" }, "mini.icons": { "branch": "main", "commit": "a2742459f0ee32806c2438ca06b4d8b331f3f4d4" }, + "nvim-cmp": { "branch": "main", "commit": "983453e32cb35533a119725883c04436d16c0120" }, "nvim-highlight-colors": { "branch": "main", "commit": "e967e2ba13fd4ca731b41d0e5cc1ac2edcd6e25e" }, "nvim-lspconfig": { "branch": "master", "commit": "056f569f71e4b726323b799b9cfacc53653bceb3" }, "nvim-solarized-lua": { "branch": "master", "commit": "d69a263c97cbc765ca442d682b3283aefd61d4ac" }, diff --git a/vim/lua/plugins/completion.lua b/vim/lua/plugins/completion.lua new file mode 100644 index 0000000..5390db4 --- /dev/null +++ b/vim/lua/plugins/completion.lua @@ -0,0 +1,76 @@ +return { + "hrsh7th/nvim-cmp", + event = "VimEnter", + dependencies = { + { + "L3MON4D3/LuaSnip", + build = (function() + return "make install_jsregexp" + end)(), + }, + "saadparwaiz1/cmp_luasnip", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + }, + config = function() + local cmp = require("cmp") + local luasnip = require("luasnip") + luasnip.config.setup({}) + + cmp.setup({ + snippet = { + expand = function(args) + vim.snippet.expand(args.body) + end, + }, + completion = { + -- Only manual completions, please + autocomplete = false, + completeopt = "menu,menuone,noinsert", + }, + + mapping = cmp.mapping.preset.insert({ + -- Scroll the documentation window [b]ack / [f]orward + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + + -- Trigger a completion from nvim-cmp. + [""] = cmp.mapping.complete({}), + + -- Think of as moving to the right of your snippet expansion. + -- So if you have a snippet that's like: + -- function $name($args) + -- $body + -- end + -- + -- will move you to the right of each of the expansion locations. + -- is similar, except moving you backwards. + [""] = cmp.mapping(function() + if luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + end + end, { "i", "s" }), + [""] = cmp.mapping(function() + if luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + end + end, { "i", "s" }), + + -- For more advanced Luasnip keymaps (e.g. selecting choice nodes, + -- expansion) see: + -- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps + }), + sources = { + { + name = "lazydev", + -- set group index to 0 to skip loading LuaLS completions as lazydev recommends it + group_index = 0, + }, + { name = "nvim_lsp" }, + { name = "buffer" }, + { name = "path" }, + }, + }) + end, +}