86 lines
3.3 KiB
Lua
86 lines
3.3 KiB
Lua
-- configure autocomplete
|
|
return {
|
|
'hrsh7th/nvim-cmp',
|
|
event = { 'InsertEnter', 'CmdlineEnter' },
|
|
dependencies = {
|
|
-- autocomplete plugins
|
|
'hrsh7th/cmp-buffer',
|
|
'hrsh7th/cmp-path',
|
|
'hrsh7th/cmp-cmdline',
|
|
'hrsh7th/cmp-nvim-lsp',
|
|
'hrsh7th/cmp-nvim-lua',
|
|
'saadparwaiz1/cmp_luasnip',
|
|
-- "hrsh7th/cmp-nvim-lsp-signature-help",
|
|
-- "hrsh7th/cmp-calc",
|
|
|
|
-- vscode like icons to autocomplete list
|
|
'onsails/lspkind.nvim',
|
|
-- snippet plugin
|
|
{ 'L3MON4D3/LuaSnip', event = { 'BufReadPost', 'BufNewFile' } },
|
|
{ 'rafamadriz/friendly-snippets', event = { 'BufReadPost', 'BufNewFile' } },
|
|
},
|
|
config = function()
|
|
local cmp = require('cmp')
|
|
local luasnip = require('luasnip')
|
|
require('luasnip/loaders/from_vscode').lazy_load()
|
|
|
|
cmp.setup({
|
|
completion = {
|
|
keyword_length = 1,
|
|
completeopt = 'menu,menuone',
|
|
},
|
|
formatting = {
|
|
fields = { 'kind', 'abbr', 'menu' },
|
|
format = function(entry, vim_item)
|
|
local kind = require('lspkind').cmp_format({ mode = 'symbol_text', maxwidth = 50 })(entry, vim_item)
|
|
local strings = vim.split(kind.kind, '%s', { trimempty = true })
|
|
kind.kind = ' ' .. (strings[1] or '') .. ' '
|
|
kind.menu = ' (' .. (strings[2] or '') .. ')'
|
|
|
|
return kind
|
|
end,
|
|
},
|
|
snippet = { -- configure how nvim-cmp interacts with snippet engine
|
|
expand = function(args)
|
|
luasnip.lsp_expand(args.body)
|
|
end,
|
|
},
|
|
mapping = {
|
|
['<Tab>'] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
|
|
['<S-Tab>'] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
|
|
['<C-k>'] = cmp.mapping.scroll_docs(-4),
|
|
['<C-j>'] = cmp.mapping.scroll_docs(4),
|
|
['<C-Space>'] = cmp.mapping.complete(), -- show completion suggestions
|
|
['<C-e>'] = cmp.mapping.abort(), -- close completion window
|
|
['<Esc>'] = cmp.mapping.close(),
|
|
['<CR>'] = cmp.mapping.confirm({
|
|
behavior = cmp.ConfirmBehavior.Insert,
|
|
select = true,
|
|
}),
|
|
},
|
|
cmp.setup.cmdline(':', {
|
|
mapping = cmp.mapping.preset.cmdline(),
|
|
sources = {
|
|
{ name = 'cmdline' },
|
|
},
|
|
}),
|
|
cmp.setup.cmdline({ '/', '?' }, {
|
|
mapping = cmp.mapping.preset.cmdline(),
|
|
sources = {
|
|
{ name = 'buffer' },
|
|
},
|
|
}),
|
|
-- sources for autocompletion
|
|
sources = {
|
|
{ name = 'nvim_lsp' },
|
|
{ name = 'luasnip' }, -- snippets
|
|
{ name = 'buffer' }, -- text within current buffer
|
|
{ name = 'path' }, -- file system paths
|
|
{ name = 'codeium' }, -- AI for autocompletion
|
|
-- { name = "nvim_lsp_signature_help" },
|
|
-- { name = "calc" }, --for maths calculations
|
|
},
|
|
})
|
|
end,
|
|
}
|