From 435e56d53a5333e00e7b932e45da371b638a2a35 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 7 Mar 2022 18:08:54 +0100 Subject: [PATCH] home: vim: completion: configure snippets --- home/vim/plugin/settings/completion.vim | 51 ++++++++++++------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/home/vim/plugin/settings/completion.vim b/home/vim/plugin/settings/completion.vim index cad93d0..5539a98 100644 --- a/home/vim/plugin/settings/completion.vim +++ b/home/vim/plugin/settings/completion.vim @@ -4,8 +4,14 @@ set completeopt=menu,menuone,noselect lua << EOF local cmp = require("cmp") local cmp_under_comparator = require("cmp-under-comparator") +local luasnip = require("luasnip") cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, mapping = { [""] = cmp.mapping({ i = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), @@ -23,32 +29,24 @@ cmp.setup({ fallback() end, }), - [""] = cmp.mapping({ - c = function(fallback) - if #cmp.core:get_sources() > 0 and not require("cmp.config").is_native_menu() then - if cmp.visible() then - cmp.select_next_item() - else - cmp.complete() - end - else - fallback() - end - end, - }), - [""] = cmp.mapping({ - c = function(fallback) - if #cmp.core:get_sources() > 0 and not require("cmp.config").is_native_menu() then - if cmp.visible() then - cmp.select_prev_item() - else - cmp.complete() - end - else - fallback() - end - end, - }), + [""] = function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, + [""] = function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, [""] = cmp.mapping(cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }), { "i", "c" }), [""] = cmp.mapping(cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }), { "i", "c" }), [""] = cmp.mapping.scroll_docs(-5), @@ -63,6 +61,7 @@ cmp.setup({ { name = "path", priority_weight = 110 }, { name = "nvim_lsp", priority_weight = 100 }, { name = "nvim_lua", priority_weight = 90 }, + { name = "luasnip", priority_weight = 80 }, { name = "buffer", max_item_count = 5, priority_weight = 50 }, }, sorting = {