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.
 
 
dotfiles/nvim/lua/plugins/nvim-cmp.lua

95 lines
3.4 KiB

return {
{
"L3MON4D3/LuaSnip",
build = "make install_jsregexp"
},
{
"hrsh7th/nvim-cmp",
dependencies = {
"hrsh7th/cmp-buffer", "hrsh7th/cmp-nvim-lsp",
"L3MON4D3/LuaSnip", "rafamadriz/friendly-snippets",
'hrsh7th/cmp-nvim-lua', 'hrsh7th/cmp-path',
'hrsh7th/cmp-calc', 'hrsh7th/cmp-cmdline', 'f3fora/cmp-spell',
},
config = function()
local cmp = require("cmp")
local luasnip = require('luasnip')
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end
},
sources = {
{ name = 'path' },
{ name = 'nvim_lsp', keyword_length = 1 },
{ name = 'buffer', keyword_length = 3 },
{ name = 'luasnip', keyword_length = 2 },
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered()
},
formatting = {
fields = { 'menu', 'abbr', 'kind' },
format = function(entry, item)
local menu_icon = {
nvim_lsp = 'λ',
luasnip = '',
buffer = 'Ω',
path = '🖫',
}
item.menu = menu_icon[entry.source.name]
return item
end,
},
mapping = {
['<Up>'] = cmp.mapping.select_prev_item(select_opts),
['<Down>'] = cmp.mapping.select_next_item(select_opts),
['<C-u>'] = cmp.mapping.scroll_docs(-4),
['<C-d>'] = cmp.mapping.scroll_docs(4),
['<C-e>'] = cmp.mapping.abort(),
['<C-y>'] = cmp.mapping.confirm({ select = true }),
['<CR>'] = cmp.mapping.confirm({ select = false }),
['<C-f>'] = 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' }),
}
})
cmp.setup.cmdline({ '/', '?' }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' }
}
})
-- to select something in the cmdline need to use <C-n>
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
}),
matching = { disallow_symbol_nonprefix_matching = false }
})
end,
} }