-
i had a problem when using nvim-cmp with vsnip, whenever I press tab when inside vsnip snippet it select the next item from nvim-cmp list instead moving to the next marker from vsnip, the vsnip keybinding is loaded before the nvim-cmp setup imap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>'
smap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>'
imap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>'
smap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>' cmp.setup{
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end
},
mapping = {
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
['<C-e>'] = cmp.mapping{
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
},
['<Tab>'] = function (fallback)
if cmp.visible() then
cmp.select_next_item()
else
fallback()
end
end,
-- Accept currently selected item. If none selected, `select` first item.
-- Set `select` to `false` to only confirm explicitly selected items.
['<CR>'] = cmp.mapping.confirm({ select = true }),
},
sources = cmp.config.sources{
{name='nvim_lua'},
{name='nvim_lsp',max_item_count=10},
{name='vsnip',max_item_count=10},
{name='buffer',keyword_length=5}
},
formatting = {
format = lspkind.cmp_format{
with_text = true,
menu = {
buffer='[BUF]',
nvim_lsp='[LSP]'
}
}
},
experimantal = {
native_menu = false,
ghost_text = true
}
}
|
Beta Was this translation helpful? Give feedback.
Answered by
dmitmel
Dec 19, 2021
Replies: 1 comment 1 reply
-
You should remove the vsnip mappings and move that logic into the nvim-cmp configuration, like this: local function replace_keys(str)
return vim.api.nvim_replace_termcodes(str, true, true, true)
end
cmp.setup({
-- ...
mapping = {
['<Tab>'] = cmp.mapping(function(fallback)
if vim.call('vsnip#available', 1) ~= 0 then
vim.fn.feedkeys(replace_keys('<Plug>(vsnip-jump-next)'), '')
elseif cmp.visible() then
cmp.select_next_item()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if vim.call('vsnip#available', -1) ~= 0 then
vim.fn.feedkeys(replace_keys('<Plug>(vsnip-jump-prev)'), '')
elseif cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end, { 'i', 's' }),
-- ...
},
-- ...
})
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
ilhamfu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should remove the vsnip mappings and move that logic into the nvim-cmp configuration, like this: