neovim/lua/plugins/cmp.lua

115 lines
2.8 KiB
Lua
Raw Normal View History

2023-09-24 01:19:07 +02:00
-- Completion plugin config
local utils = require('utils')
2024-01-04 00:45:21 +01:00
utils.opt('o', 'completeopt', 'menuone,noselect')
2023-09-24 01:19:07 +02:00
local cmp = require('cmp')
2024-01-04 00:45:21 +01:00
local cmp_kinds = {
2024-04-18 14:49:55 +02:00
Text = '',
Method = '󰊕 ',
Function = '󰊕 ',
Constructor = '',
Field = '',
Variable = '',
Class = '',
Interface = '',
Module = '',
Property = '',
Unit = '',
Value = '',
Enum = '',
Keyword = '',
Snippet = '',
Color = '',
File = '',
Reference = '',
Folder = '',
EnumMember = '',
Constant = '',
Struct = '',
Event = '',
Operator = '',
TypeParameter = '',
2024-01-04 00:45:21 +01:00
}
2023-09-24 01:19:07 +02:00
cmp.setup({
2024-01-04 00:45:21 +01:00
formatting = {
format = function(entry, vim_item)
-- Kind icons
vim_item.kind = string.format('%s %s', cmp_kinds[vim_item.kind], vim_item.kind)
vim_item.menu = ({
buffer = "[Buffer]",
nvim_lsp = "[LSP]",
luasnip = "[LuaSnip]",
nvim_lua = "[Lua]",
latex_symbols = "[LaTeX]",
})[entry.source.name]
return vim_item
end
},
2023-09-24 01:19:07 +02:00
snippet = {
2024-03-20 01:12:42 +01:00
expand = function(args)
local luasnip = require("luasnip")
if not luasnip then
return
end
luasnip.lsp_expand(args.body)
end,
2023-09-24 01:19:07 +02:00
},
window = {
completion = {
border = nil,
},
documentation = {
border = nil,
max_height = 2000,
}
},
completion = {
autocomplete = false,
2023-09-24 01:19:07 +02:00
},
mapping = cmp.mapping.preset.insert({
2024-03-20 12:49:43 +01:00
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-x><C-o>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
-- Accept currently selected item.
-- Set `select` to `false` to only confirm explicitly selected items.
['<CR>'] = cmp.mapping.confirm({ select = false }),
2023-09-24 01:19:07 +02:00
}),
sources = cmp.config.sources({
2024-03-20 12:49:43 +01:00
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
2023-09-24 01:19:07 +02:00
}, {
2024-03-20 12:49:43 +01:00
{ name = 'buffer' },
2023-09-24 01:19:07 +02:00
})
})
-- Set configuration for specific filetype.
2024-03-20 12:49:43 +01:00
cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({
{ name = 'git' },
}, {
{ name = 'buffer' },
})
})
2023-09-24 01:19:07 +02:00
-- 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' }
})
})