1
0
Fork 0
numbers/.config/nvim/plugin/completar.lua

76 lines
2.0 KiB
Lua

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
local feedkey = function(key, mode)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
end
local cmp = require'cmp'
cmp.setup({
formatting = {
format = require('lspkind').cmp_format({with_text=true, menu = ({
buffer = " [Buff]",
nvim_lsp = " [LSP]",
vsnip = " [Snip]",
nvim_lua = " [Lua]",
look = " [Dict]",
spell = " [Spell]"
}),
}),
-- format = require('lspkind').cmp_format({with_text = true, maxwidth = 50})
-- format = function(entry, vim_item)
-- -- fancy icons and a name of kind
-- vim_item.kind = require('lspkind').presets.default[vim_item.kind]
-- -- set a name for each source
-- vim_item.menu = ({
-- buffer = " [Buff]",
-- nvim_lsp = " [LSP]",
-- vsnip = " [Snip]",
-- nvim_lua = " [Lua]",
-- look = " [Dict]",
-- spell = " [Spell]"
-- })[entry.source.name]
-- return vim_item
-- end,
},
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
mapping = {
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm({ select = true }),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif vim.fn["vsnip#available"]() == 1 then
feedkey("<Plug>(vsnip-expand-or-jump)", "")
elseif has_words_before() then
cmp.complete()
else
fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function()
if cmp.visible() then
cmp.select_prev_item()
elseif vim.fn["vsnip#jumpable"](-1) == 1 then
feedkey("<Plug>(vsnip-jump-prev)", "")
end
end, { "i", "s" }),
},
sources = {
{ name = 'buffer' },
}
})