You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.8 KiB
81 lines
2.8 KiB
2 years ago
|
local cmp = require('cmp')
|
||
|
local luasnip = require('luasnip')
|
||
|
|
||
|
local select_opts = { behavior = cmp.SelectBehavior.Select }
|
||
|
local has_words_before = function()
|
||
|
-- local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||
|
local line, col = table.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 {
|
||
|
enabled = true,
|
||
|
preselect = cmp.PreselectMode.None,
|
||
|
snippet = { expand = function(args) luasnip.lsp_expand(args.body) end },
|
||
|
sources = {
|
||
|
{ name = 'path' }, { name = 'nvim_lsp' },
|
||
|
-- { name = 'buffer', keyword_length = 3 },
|
||
|
{ name = 'buffer' }, { name = 'luasnip', keyword_length = 3 },
|
||
|
-- { name = 'cmdline' },
|
||
|
{ name = "cmp_tabnine" }, { name = "nvim_lua" },
|
||
|
{ name = 'buffer' },
|
||
|
{ name = "neorg" },
|
||
|
},
|
||
|
mapping = cmp.mapping.preset.insert({
|
||
|
['<C-p>'] = cmp.mapping.select_prev_item(select_opts),
|
||
|
['<C-n>'] = cmp.mapping.select_next_item(select_opts),
|
||
|
['<Tab>'] = cmp.mapping.select_next_item(select_opts),
|
||
|
['<C-y>'] = cmp.mapping.confirm({ select = true }),
|
||
|
['<Enter>'] = cmp.mapping.confirm({ select = true }),
|
||
|
["<C-Space>"] = cmp.mapping.complete(),
|
||
|
['<C-u>'] = cmp.mapping.scroll_docs(-4),
|
||
|
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
||
|
['<C-d>'] = cmp.mapping(function(fallback)
|
||
|
if luasnip.jumpable(1) then
|
||
|
luasnip.jump(1)
|
||
|
else
|
||
|
fallback()
|
||
|
end
|
||
|
end, { 'i', 's' }),
|
||
|
['<C-b>'] = cmp.mapping(function(fallback)
|
||
|
if luasnip.jumpable(-1) then
|
||
|
luasnip.jump(-1)
|
||
|
else
|
||
|
fallback()
|
||
|
end
|
||
|
end, { 'i', 's' })
|
||
|
}),
|
||
|
window = { documentation = cmp.config.window.bordered() },
|
||
|
formatting = {
|
||
|
fields = { 'menu', 'abbr', 'kind' },
|
||
|
format = function(entry, item)
|
||
|
local menu_icon = {
|
||
|
nvim_lsp = '[lsp]',
|
||
|
luasnip = '[snip]',
|
||
|
buffer = '[buf]',
|
||
|
path = '[path]',
|
||
|
--cmdline = "[cmd]",
|
||
|
cmp_tabnine = "[tab]",
|
||
|
}
|
||
|
|
||
|
item.menu = menu_icon[entry.source.name]
|
||
|
return item
|
||
|
end
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
|
||
|
cmp.setup.cmdline({ '/', '?' }, {
|
||
|
mapping = cmp.mapping.preset.cmdline(),
|
||
|
sources = { { name = 'buffer' } }
|
||
|
})
|
||
|
|
||
|
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
|
||
|
cmp.setup.cmdline(':', {
|
||
|
mapping = cmp.mapping.preset.cmdline(),
|
||
|
sources = cmp.config.sources({ { name = 'path' } }, { { name = 'cmdline' } })
|
||
|
})
|