replace luasnip with vsnip

This commit is contained in:
Dietrich Rink
2023-06-10 15:18:53 +02:00
parent 06d8ff3713
commit bd11cd4ed2
9 changed files with 38 additions and 64 deletions

View File

@@ -1,13 +1,18 @@
local cmp = require 'cmp'
local context = require 'cmp.config.context'
local luasnip = require 'luasnip'
vim.o.completeopt = nil
-- Plugin helper
local feedkey = function(key, mode)
key = vim.api.nvim_replace_termcodes(key, true, true, true)
vim.api.nvim_feedkeys(key, mode, true)
end
-- General setup
cmp.setup {
snippet = {
expand = function(args) luasnip.lsp_expand(args.body) end,
expand = function(args) vim.fn['vsnip#anonymous'](args.body) end,
},
window = {
documentation = { border = 'rounded' },
@@ -17,7 +22,7 @@ cmp.setup {
format = function(entry, item)
item.menu = ({
nvim_lsp = 'λ',
luasnip = '',
vsnip = '',
buffer = 'Ω',
path = '🖫',
})[entry.source.name]
@@ -30,10 +35,10 @@ cmp.setup {
['<tab>'] = cmp.mapping(function(fallback)
if cmp.get_selected_entry() then
cmp.confirm()
elseif luasnip.jumpable(1) then
luasnip.jump(1)
elseif luasnip.expandable() then
luasnip.expand()
elseif vim.fn['vsnip#jumpable'](1) == 1 then
feedkey('<plug>(vsnip-jump-next)', '')
elseif vim.fn['vsnip#expandable']() == 1 then
feedkey('<plug>(vsnip-expand)', '')
elseif cmp.visible() then
cmp.select_next_item()
else
@@ -42,8 +47,8 @@ cmp.setup {
end, { 'i', 's' }),
-- Jump back with shift tab
['<s-tab>'] = cmp.mapping(function(fallback)
if luasnip.jumpable(-1) then
luasnip.jump(-1)
if vim.fn['vsnip#jumpable'](-1) == 1 then
feedkey('<plug>(vsnip-jump-prev)', '')
else
fallback()
end
@@ -57,12 +62,16 @@ cmp.setup {
end
end),
['<c-p>'] = cmp.mapping(function(fallback)
if cmp.visible() then cmp.select_prev_item() else fallback() end
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end),
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
{ name = 'vsnip' },
{ name = 'nvim_lua' },
}, {
{ name = 'buffer', keyword_length = 5 },