From c42a75128a165eb6efcdfac449373543d1109297 Mon Sep 17 00:00:00 2001 From: Vegard Berg Date: Mon, 22 May 2023 22:15:55 +0200 Subject: [PATCH] Added configuration for nvim-cmp, with cmp-nvim-lsp and nvim-lspconfig. --- init.lua | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index ef8db00..4e94896 100644 --- a/init.lua +++ b/init.lua @@ -27,11 +27,11 @@ function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...) return orig_util_open_floating_preview(contents, syntax, opts, ...) end ---[[ +--[==========[ ░█░░░█▀█░▀▀█░█░█░░░░█▀█░█░█░▀█▀░█▄█ ░█░░░█▀█░▄▀░░░█░░░░░█░█░▀▄▀░░█░░█░█ ░▀▀▀░▀░▀░▀▀▀░░▀░░▀░░▀░▀░░▀░░▀▀▀░▀░▀ -]]-- +--]==========] local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not vim.loop.fs_stat(lazypath) then vim.fn.system({ @@ -47,3 +47,66 @@ vim.opt.rtp:prepend(lazypath) require("lazy").setup("plugins") + +--[==========[ +░█▀█░█░█░▀█▀░█▄█░░░░░█▀▀░█▄█░█▀█ +░█░█░▀▄▀░░█░░█░█░▄▄▄░█░░░█░█░█▀▀ +░▀░▀░░▀░░▀▀▀░▀░▀░░░░░▀▀▀░▀░▀░▀░░ +--]==========] +local cmp = require'cmp' + +cmp.setup({ +snippet = { + -- REQUIRED - you must specify a snippet engine + expand = function(args) + require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + end, +}, +window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), +}, +mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = 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. +}), +sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'luasnip' }, -- For luasnip users. +}, { + { name = 'buffer' }, +}) +}) + +-- Set configuration for specific filetype. +cmp.setup.filetype('gitcommit', { +sources = cmp.config.sources({ + { name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it. +}, { + { name = 'buffer' }, +}) +}) + +-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). +cmp.setup.cmdline({ '/', '?' }, { +mapping = cmp.mapping.preset.cmdline(), +sources = { + { name = 'buffer' } +} +}) + +-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). +cmp.setup.cmdline(':', { +mapping = cmp.mapping.preset.cmdline(), +sources = cmp.config.sources({ + { name = 'path' } +}, { + { name = 'cmdline' } +}) +}) + +-- Set up lspconfig. +local capabilities = require('cmp_nvim_lsp').default_capabilities()