From 7753a46a6b7c6ef7e906a0a10f798e530b1a3f9a Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Mon, 2 Jan 2023 09:49:09 +0100 Subject: [PATCH] feat(cmp): better tab behavior for cmp and luasnip --- lua/lazyvim/plugins/coding.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lua/lazyvim/plugins/coding.lua b/lua/lazyvim/plugins/coding.lua index b6661263..38058064 100644 --- a/lua/lazyvim/plugins/coding.lua +++ b/lua/lazyvim/plugins/coding.lua @@ -36,6 +36,26 @@ return { [""] = cmp.mapping.complete(), [""] = cmp.mapping.abort(), [""] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + [""] = cmp.mapping(function(fallback) + local luasnip = require("luasnip") + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + local luasnip = require("luasnip") + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { "i", "s" }), }), sources = cmp.config.sources({ { name = "nvim_lsp" },