diff options
Diffstat (limited to 'after')
-rw-r--r-- | after/plugin/cmp.lua | 23 |
1 files 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({ ["<Tab>"] = 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" }), - ['<CR>'] = cmp.mapping.confirm({ select = true }), + ['<CR>'] = 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 }), + }), ['<ESC>'] = cmp.mapping.close(), }), + sorting = { comparators = { cmp.config.compare.offset, |