From 52722fb408ac1c2e8e2b824b27a242651fa2a26a Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 7 Mar 2022 14:50:59 +0100 Subject: [PATCH] home: vim: completion: explicit mappings This is basically a copy-paste of the default mappings, with some small amount of customization. --- home/vim/plugin/settings/completion.vim | 48 +++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/home/vim/plugin/settings/completion.vim b/home/vim/plugin/settings/completion.vim index 0d0507f..1553c2b 100644 --- a/home/vim/plugin/settings/completion.vim +++ b/home/vim/plugin/settings/completion.vim @@ -5,6 +5,54 @@ lua << EOF local cmp = require("cmp") cmp.setup({ + mapping = { + [""] = cmp.mapping({ + i = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), + c = function(fallback) + cmp.close() + vim.schedule(cmp.suspend()) + fallback() + end, + }), + [""] = cmp.mapping({ + i = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), + c = function(fallback) + cmp.close() + vim.schedule(cmp.suspend()) + fallback() + end, + }), + [""] = cmp.mapping({ + c = function(fallback) + if #cmp.core:get_sources() > 0 and not require("cmp.config").is_native_menu() then + if cmp.visible() then + cmp.select_next_item() + else + cmp.complete() + end + else + fallback() + end + end, + }), + [""] = cmp.mapping({ + c = function(fallback) + if #cmp.core:get_sources() > 0 and not require("cmp.config").is_native_menu() then + if cmp.visible() then + cmp.select_prev_item() + else + cmp.complete() + end + else + fallback() + end + end, + }), + [""] = cmp.mapping(cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }), { "i", "c" }), + [""] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = false }), + [""] = cmp.mapping.abort(), + }, view = { entries = "native", },