From 72fbdb3be79f235540a5403fc88d5f45d53b1af6 Mon Sep 17 00:00:00 2001 From: Squibid Date: Thu, 6 Jul 2023 12:29:38 -0400 Subject: better movement while using cmp --- after/plugin/cmp.lua | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/after/plugin/cmp.lua b/after/plugin/cmp.lua index a3a7094..a8b7937 100644 --- a/after/plugin/cmp.lua +++ b/after/plugin/cmp.lua @@ -38,6 +38,12 @@ local has_words_before = function() [1]:sub(col, col):match("%s") == nil end +-- insert '(' after completing a function +cmp.event:on( + 'confirm_done', + require('nvim-autopairs.completion.cmp').on_confirm_done() +) + local luasnip = require('luasnip') require("luasnip.loaders.from_vscode").lazy_load() @@ -81,11 +87,13 @@ cmp.setup { return vim_item end }, + + -- mappings ----------------------------------------------------------------- mapping = cmp.mapping.preset.insert({ [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() - elseif luasnip.expand_or_jumpable() then + elseif luasnip.expand_or_locally_jumpable() then luasnip.expand_or_jump() elseif has_words_before() then cmp.complete() @@ -102,9 +110,20 @@ cmp.setup { fallback() end end, { "i", "s" }), - [''] = cmp.mapping.confirm({ select = true }), + [''] = 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 }), + }), [''] = cmp.mapping.close(), }), + sorting = { comparators = { cmp.config.compare.offset, -- cgit v1.2.1