diff options
author | Squibid <me@zacharyscheiman.com> | 2023-07-06 12:29:38 -0400 |
---|---|---|
committer | Squibid <me@zacharyscheiman.com> | 2023-07-06 12:29:38 -0400 |
commit | 72fbdb3be79f235540a5403fc88d5f45d53b1af6 (patch) | |
tree | 0c3ee95d04eef0d20a174e093f281c01beed62c8 /after/plugin/cmp.lua | |
parent | a45e5e40742f24e4896383d1554ea5b7a0524e60 (diff) | |
download | nvim-72fbdb3be79f235540a5403fc88d5f45d53b1af6.tar.gz nvim-72fbdb3be79f235540a5403fc88d5f45d53b1af6.tar.bz2 nvim-72fbdb3be79f235540a5403fc88d5f45d53b1af6.zip |
better movement while using cmp
Diffstat (limited to 'after/plugin/cmp.lua')
-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, |