From c8fd1b41637f66efc2324c935adb68a3c87796a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9ana=20=E6=B1=9F?= Date: Fri, 18 Jul 2025 20:49:11 +0200 Subject: [PATCH] nvim/cmp: add simple luasnip binding to nvim-cmp --- .config/nvim/plugin/cmp.lua | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/.config/nvim/plugin/cmp.lua b/.config/nvim/plugin/cmp.lua index ff9b5216..3fc67eb3 100644 --- a/.config/nvim/plugin/cmp.lua +++ b/.config/nvim/plugin/cmp.lua @@ -7,14 +7,29 @@ cmp.setup { snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, - mapping = cmp.mapping.preset.insert(), + mapping = cmp.mapping.preset.insert { + [""] = cmp.mapping(function(fallback) + if luasnip.locally_jumpable(1) then + luasnip.jump(1) + else + fallback() + end + end, { "i", "s" }), + + [""] = cmp.mapping(function(fallback) + if luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { "i", "s" }), + }, sources = cmp.config.sources({ - { name = "luasnip" }, - { name = "nvim_lsp" }, - { name = "path" }, - }, - { - { name = "buffer" }, - { name = "spell", }, - }), + { name = "luasnip" }, + { name = "nvim_lsp" }, + { name = "path" }, + }, { + { name = "buffer" }, + { name = "spell" }, + }), }