Fix: cmp mapping (tab to confirm)

This commit is contained in:
Bertrand Benjamin 2022-02-03 10:26:39 +01:00
parent ecf6b9fb6a
commit 4e6384ac3e

View File

@ -65,26 +65,26 @@ cmp.setup{
}, },
mapping = { mapping = {
-- ["<cr>"] = cmp.mapping.confirm({select = true, behavior = cmp.ConfirmBehavior.Replace}), -- ["<cr>"] = cmp.mapping.confirm({select = true, behavior = cmp.ConfirmBehavior.Replace}),
["<cr>"] = cmp.mapping.confirm({select = true, behavior = cmp.ConfirmBehavior.Insert}), ["<Tab>"] = cmp.mapping.confirm({select = true, behavior = cmp.ConfirmBehavior.Insert}),
["<Tab>"] = cmp.mapping(function(fallback) -- ["<Tab>"] = cmp.mapping(function(fallback)
if vim.fn.pumvisible() == 1 then -- if vim.fn.pumvisible() == 1 then
feedkey("<C-n>", "n") -- feedkey("<C-n>", "n")
elseif vim.fn["vsnip#available"]() == 1 then -- elseif vim.fn["vsnip#available"]() == 1 then
feedkey("<Plug>(vsnip-expand-or-jump)", "") -- feedkey("<Plug>(vsnip-expand-or-jump)", "")
elseif has_words_before() then -- elseif has_words_before() then
cmp.complete() -- cmp.complete()
else -- else
fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`. -- fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
end -- end
end, { "i", "s" }), -- end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function() -- ["<S-Tab>"] = cmp.mapping(function()
if vim.fn.pumvisible() == 1 then -- if vim.fn.pumvisible() == 1 then
feedkey("<C-p>", "n") -- feedkey("<C-p>", "n")
elseif vim.fn["vsnip#jumpable"](-1) == 1 then -- elseif vim.fn["vsnip#jumpable"](-1) == 1 then
feedkey("<Plug>(vsnip-jump-prev)", "") -- feedkey("<Plug>(vsnip-jump-prev)", "")
end -- end
end, { "i", "s" }), -- end, { "i", "s" }),
}, },
sources = { sources = {
{ name = 'vsnip' }, { name = 'vsnip' },