From 4e9cefd541deca4170f944da58eea66a8f478f04 Mon Sep 17 00:00:00 2001 From: Daniel Patterson Date: Tue, 7 Nov 2023 12:35:29 +0000 Subject: [PATCH] Fix nvim-cmp keymap --- lua/plugins/core.lua | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/lua/plugins/core.lua b/lua/plugins/core.lua index ef8382c..0fd81e2 100644 --- a/lua/plugins/core.lua +++ b/lua/plugins/core.lua @@ -17,11 +17,33 @@ return { lazy = false, }, { - "folke/flash.nvim", - keys = { - { "s", mode = { "n", "x", "o" }, false }, - { "S", mode = { "n", "x", "o" }, false }, - }, + "folke/flash.nvim", + keys = { + { "s", mode = { "n", "x", "o" }, false }, + { "S", mode = { "n", "x", "o" }, false }, + }, + }, + { + "hrsh7th/nvim-cmp", + opts = function(_, opts) + local cmp = require("cmp") + opts.mapping[""] = cmp.mapping({ + i = function(fallback) + if cmp.visible() and cmp.get_active_entry() then + cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false }) + else + fallback() + end + end, + s = cmp.mapping.confirm({ select = true }), + c = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }), + }) + opts.mapping[""] = nil + opts.mapping[""] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }) + opts.mapping[""] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }) + opts.completion.completeopt = "menu,menuone,noselect" + opts.preselect = cmp.PreselectMode.None + end, }, { "L3MON4D3/LuaSnip",