|
| 1 | +return { -- Autocompletion |
| 2 | + "hrsh7th/nvim-cmp", |
| 3 | + event = "InsertEnter", |
| 4 | + dependencies = { |
| 5 | + -- Snippet Engine & its associated nvim-cmp source |
| 6 | + { |
| 7 | + "L3MON4D3/LuaSnip", |
| 8 | + build = (function() |
| 9 | + -- Build Step is needed for regex support in snippets. |
| 10 | + -- This step is not supported in many windows environments. |
| 11 | + -- Remove the below condition to re-enable on windows. |
| 12 | + if vim.fn.has("win32") == 1 or vim.fn.executable("make") == 0 then |
| 13 | + return |
| 14 | + end |
| 15 | + return "make install_jsregexp" |
| 16 | + end)(), |
| 17 | + dependencies = { |
| 18 | + -- `friendly-snippets` contains a variety of premade snippets. |
| 19 | + -- See the README about individual language/framework/plugin snippets: |
| 20 | + -- https://github.com/rafamadriz/friendly-snippets |
| 21 | + -- { |
| 22 | + -- 'rafamadriz/friendly-snippets', |
| 23 | + -- config = function() |
| 24 | + -- require('luasnip.loaders.from_vscode').lazy_load() |
| 25 | + -- end, |
| 26 | + -- }, |
| 27 | + }, |
| 28 | + }, |
| 29 | + "saadparwaiz1/cmp_luasnip", |
| 30 | + |
| 31 | + -- Adds other completion capabilities. |
| 32 | + -- nvim-cmp does not ship with all sources by default. They are split |
| 33 | + -- into multiple repos for maintenance purposes. |
| 34 | + "hrsh7th/cmp-nvim-lsp", |
| 35 | + "hrsh7th/cmp-path", |
| 36 | + }, |
| 37 | + config = function() |
| 38 | + -- See `:help cmp` |
| 39 | + local cmp = require("cmp") |
| 40 | + local luasnip = require("luasnip") |
| 41 | + luasnip.config.setup({}) |
| 42 | + |
| 43 | + cmp.setup({ |
| 44 | + snippet = { |
| 45 | + expand = function(args) |
| 46 | + luasnip.lsp_expand(args.body) |
| 47 | + end, |
| 48 | + }, |
| 49 | + completion = { completeopt = "menu,menuone,noinsert" }, |
| 50 | + |
| 51 | + -- For an understanding of why these mappings were |
| 52 | + -- chosen, you will need to read `:help ins-completion` |
| 53 | + -- |
| 54 | + -- No, but seriously. Please read `:help ins-completion`, it is really good! |
| 55 | + mapping = cmp.mapping.preset.insert({ |
| 56 | + -- Select the [n]ext item |
| 57 | + ["<C-n>"] = cmp.mapping.select_next_item(), |
| 58 | + -- Select the [p]revious item |
| 59 | + ["<C-p>"] = cmp.mapping.select_prev_item(), |
| 60 | + |
| 61 | + -- Scroll the documentation window [b]ack / [f]orward |
| 62 | + ["<C-b>"] = cmp.mapping.scroll_docs(-4), |
| 63 | + ["<C-f>"] = cmp.mapping.scroll_docs(4), |
| 64 | + |
| 65 | + -- Accept ([y]es) the completion. |
| 66 | + -- This will auto-import if your LSP supports it. |
| 67 | + -- This will expand snippets if the LSP sent a snippet. |
| 68 | + ["<C-y>"] = cmp.mapping.confirm({ select = true }), |
| 69 | + |
| 70 | + -- If you prefer more traditional completion keymaps, |
| 71 | + -- you can uncomment the following lines |
| 72 | + --['<CR>'] = cmp.mapping.confirm { select = true }, |
| 73 | + --['<Tab>'] = cmp.mapping.select_next_item(), |
| 74 | + --['<S-Tab>'] = cmp.mapping.select_prev_item(), |
| 75 | + |
| 76 | + -- Manually trigger a completion from nvim-cmp. |
| 77 | + -- Generally you don't need this, because nvim-cmp will display |
| 78 | + -- completions whenever it has completion options available. |
| 79 | + ["<C-Space>"] = cmp.mapping.complete({}), |
| 80 | + |
| 81 | + -- Think of <c-l> as moving to the right of your snippet expansion. |
| 82 | + -- So if you have a snippet that's like: |
| 83 | + -- function $name($args) |
| 84 | + -- $body |
| 85 | + -- end |
| 86 | + -- |
| 87 | + -- <c-l> will move you to the right of each of the expansion locations. |
| 88 | + -- <c-h> is similar, except moving you backwards. |
| 89 | + ["<C-l>"] = cmp.mapping(function() |
| 90 | + if luasnip.expand_or_locally_jumpable() then |
| 91 | + luasnip.expand_or_jump() |
| 92 | + end |
| 93 | + end, { "i", "s" }), |
| 94 | + ["<C-h>"] = cmp.mapping(function() |
| 95 | + if luasnip.locally_jumpable(-1) then |
| 96 | + luasnip.jump(-1) |
| 97 | + end |
| 98 | + end, { "i", "s" }), |
| 99 | + |
| 100 | + -- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see: |
| 101 | + -- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps |
| 102 | + }), |
| 103 | + sources = { |
| 104 | + { name = "nvim_lsp" }, |
| 105 | + { name = "luasnip" }, |
| 106 | + { name = "path" }, |
| 107 | + }, |
| 108 | + }) |
| 109 | + end, |
| 110 | +} |
0 commit comments