fix: setup luasnip to work with cmp
This commit is contained in:
parent
cae629670a
commit
8e643a37f7
@ -3,6 +3,12 @@ local lspkind = require('lspkind')
|
||||
lspkind.init()
|
||||
|
||||
local cmp = require('cmp')
|
||||
local luasnip = require("luasnip")
|
||||
|
||||
local has_words_before = function()
|
||||
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
|
||||
end
|
||||
|
||||
cmp.setup{
|
||||
completion = { completeopt = 'menu,menuone,noinsert' },
|
||||
@ -12,8 +18,6 @@ cmp.setup{
|
||||
end,
|
||||
},
|
||||
mapping = {
|
||||
-- ['<C-n>'] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
|
||||
-- ['<C-p>'] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
|
||||
['<C-d>'] = cmp.mapping.scroll_docs(-4),
|
||||
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
||||
['<C-Space>'] = cmp.mapping.complete(),
|
||||
@ -21,7 +25,29 @@ cmp.setup{
|
||||
['<CR>'] = cmp.mapping.confirm({
|
||||
behavior = cmp.ConfirmBehavior.Insert,
|
||||
select = true,
|
||||
})
|
||||
}),
|
||||
|
||||
["<C-n>"] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
elseif luasnip.expand_or_jumpable() then
|
||||
luasnip.expand_or_jump()
|
||||
elseif has_words_before() then
|
||||
cmp.complete()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
|
||||
["<C-p>"] = 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" }),
|
||||
},
|
||||
sources = {
|
||||
{ name = 'emoji', max_item_count = 10, keyword_length = 5 },
|
||||
@ -53,7 +79,6 @@ cmp.setup{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-- Use buffer source for `/`.
|
||||
cmp.setup.cmdline('/', {
|
||||
sources = {
|
||||
|
Loading…
Reference in New Issue
Block a user