From 415fcc08aee197b50c7c8c12c96b0d88f2ec25c7 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Wed, 18 May 2022 10:22:09 +0200 Subject: [PATCH] feat: only confirm autocomplete with enter if item selected --- nvim/lua/plugins/nvim-cmp.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/nvim/lua/plugins/nvim-cmp.lua b/nvim/lua/plugins/nvim-cmp.lua index ce92738..ebe6601 100644 --- a/nvim/lua/plugins/nvim-cmp.lua +++ b/nvim/lua/plugins/nvim-cmp.lua @@ -22,9 +22,15 @@ cmp.setup({ { name = "calc" } }), mapping = { - [''] = cmp.mapping(cmp.mapping.complete(), - { 'i', 'c' }), - [''] = cmp.mapping.confirm({ select = true }), + [""] = cmp.mapping(cmp.mapping.complete(), + { "i", "c" }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() and cmp.get_selected_entry() then + cmp.confirm() + else + fallback() + end + end, { "i", "s" }), [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item()