From 3c37004e9d616689f997ccb5638d6df5a7981cd5 Mon Sep 17 00:00:00 2001 From: Daniel Lundin Date: Wed, 8 Mar 2023 11:04:13 +0100 Subject: [PATCH] nvim: clean up cmp config --- .config/nvim/lua/plugins/cmp.lua | 99 ++++++++++---------------------- 1 file changed, 30 insertions(+), 69 deletions(-) diff --git a/.config/nvim/lua/plugins/cmp.lua b/.config/nvim/lua/plugins/cmp.lua index c52f363..ddba684 100644 --- a/.config/nvim/lua/plugins/cmp.lua +++ b/.config/nvim/lua/plugins/cmp.lua @@ -1,4 +1,4 @@ -local M = { +return { "hrsh7th/nvim-cmp", dependencies = { "andersevenrud/cmp-tmux", @@ -9,75 +9,36 @@ local M = { "hrsh7th/cmp-cmdline", "hrsh7th/cmp-nvim-lsp-signature-help", "onsails/lspkind-nvim", + { "zbirenbaum/copilot-cmp", opts = {} }, }, event = "InsertEnter", -} + config = function() + local cmp = require("cmp") -function M.config() - local cmp = require("cmp") - - local has_words_before = function() - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil - end - - vim.o.completeopt = "menuone,noselect" - - cmp.setup({ - completion = { - completeopt = "menu,menuone,noinsert", - }, - - formatting = { - format = require("lspkind").cmp_format(), - }, - - window = { - completion = cmp.config.window.bordered({ - winhighlight = "Normal:PMenu,FloatBorder:PMenuBorder,CursorLine:PMenuSel,Search:None", - }), - documentation = cmp.config.window.bordered({ - winhighlight = "Normal:PMenu,FloatBorder:PMenu,CursorLine:PMenuSel,Search:None", - }), - }, - - mapping = { - [""] = cmp.mapping(cmp.mapping.select_prev_item(), { "i", "c" }), - [""] = cmp.mapping(cmp.mapping.select_next_item(), { "i", "c" }), - [""] = cmp.mapping.scroll_docs(-2), - [""] = cmp.mapping.scroll_docs(2), - [""] = cmp.mapping({ - i = cmp.mapping.abort(), - c = cmp.mapping.close(), - }), - -- [""] = cmp.mapping(cmp.mapping.confirm({ select = false }), { "i", "c" }), - -- [""] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), - [""] = cmp.mapping(cmp.mapping.confirm({ select = true })), - [""] = cmp.mapping(cmp.mapping.complete(), {}), - }, - - -- experimental = { - -- ghost_text = { - -- hl_group = "LspCodeLens", - -- }, - -- }, - - sources = cmp.config.sources({ - { name = "nvim_lsp" }, - { name = "nvim_lsp_signature_help" }, - { name = "buffer" }, - { name = "copilot" }, - { - name = "tmux", - priority = 2, - option = { - all_panes = true, - trigger_characters = {}, - }, + cmp.setup({ + formatting = { + format = require("lspkind").cmp_format(), }, - { name = "emoji" }, - }), - }) -end - -return M + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping.scroll_docs(-2), + [""] = cmp.mapping.scroll_docs(2), + [""] = cmp.mapping.abort(), + [""] = cmp.mapping.confirm({ select = true }), + [""] = cmp.mapping.complete(), + }), + sources = cmp.config.sources({ + { name = "nvim_lsp" }, + { name = "nvim_lsp_signature_help" }, + { name = "buffer" }, + { name = "copilot" }, + { name = "emoji" }, + }), + }) + end, +}