From 9d10cb05a2199eefb43d6f6ebdd48a2af9b7cdaa Mon Sep 17 00:00:00 2001 From: "flyingscorpio@clevo" Date: Sat, 13 Aug 2022 13:57:27 +0200 Subject: [PATCH] Integrate tab for luasnip and completion --- .../files/lua/plugins/options/completion.lua | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/roles/neovim/files/lua/plugins/options/completion.lua b/roles/neovim/files/lua/plugins/options/completion.lua index 497ede0..b168c09 100644 --- a/roles/neovim/files/lua/plugins/options/completion.lua +++ b/roles/neovim/files/lua/plugins/options/completion.lua @@ -1,7 +1,10 @@ -- Completion vim.opt.completeopt = { 'menu', 'menuone', 'noselect' } + +local luasnip = require'luasnip' local cmp = require'cmp' + if cmp then cmp.setup({ snippet = { @@ -18,8 +21,24 @@ if cmp then [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.complete(), [''] = cmp.mapping.abort(), - [''] = cmp.mapping.select_next_item(), - [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping(function (fallback) + 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) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { 'i', 's' }), [''] = cmp.mapping.confirm({ select = false }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. }), sources = cmp.config.sources({