From 7339958a08b87493d4820562a83f380d142f32b2 Mon Sep 17 00:00:00 2001 From: tastytea Date: Fri, 12 Aug 2022 19:19:20 +0200 Subject: [PATCH] nvim: cmp: dwim tab --- .config/nvim/lua/my/completion.lua | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/.config/nvim/lua/my/completion.lua b/.config/nvim/lua/my/completion.lua index 7a304ae..ea7455c 100644 --- a/.config/nvim/lua/my/completion.lua +++ b/.config/nvim/lua/my/completion.lua @@ -17,13 +17,14 @@ packer.use { }, config = function() local cmp = require'cmp' - if cmp == nil then - return - end + if not cmp then return end + local luasnip = require('luasnip') + if not luasnip then return end + cmp.setup({ snippet = { expand = function(args) - require('luasnip').lsp_expand(args.body) + luasnip.lsp_expand(args.body) end, }, window = { @@ -37,7 +38,26 @@ packer.use { [''] = cmp.mapping.abort(), [''] = cmp.mapping.abort(), [''] = cmp.mapping.confirm({ select = false }), - [''] = cmp.mapping.confirm({ select = true }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expandable() then + luasnip.expand() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.kump(-1) + else + fallback() + end + end) }), sources = cmp.config.sources({ { name = 'nvim_lsp' },