nix-config/home/neovim/lua/plugins/cmp.lua

54 lines
2.1 KiB
Lua

return {
"hrsh7th/nvim-cmp", -- Autocompletion plugin
dependencies = {
"hrsh7th/cmp-nvim-lsp", -- LSP source for nvim-cmp
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"saadparwaiz1/cmp_luasnip", -- Snippets source for nvim-cmp
"L3MON4D3/LuaSnip", -- Snippets plugin
},
config = function()
require('cmp').setup {
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
mapping = require('cmp').mapping.preset.insert({
['<C-u>'] = require('cmp').mapping.scroll_docs(-4), -- Up
['<C-d>'] = require('cmp').mapping.scroll_docs(4), -- Down
-- C-b (back) C-f (forward) for snippet placeholder navigation.
['<C-Space>'] = require('cmp').mapping.complete(),
['<CR>'] = require('cmp').mapping.confirm {
behavior = require('cmp').ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = require('cmp').mapping(function(fallback)
if require('cmp').visible() then
require('cmp').select_next_item()
elseif require('luasnip').expand_or_jumpable() then
require('luasnip').expand_or_jump()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = require('cmp').mapping(function(fallback)
if require('cmp').visible() then
require('cmp').select_prev_item()
elseif require('luasnip').jumpable(-1) then
require('luasnip').jump(-1)
else
fallback()
end
end, { 'i', 's' }),
}),
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
{ name = 'buffer' },
{ name = 'path' },
},
}
end,
}