Skip to content

Instantly share code, notes, and snippets.

@Saghen
Created March 31, 2025 13:29
Show Gist options
  • Save Saghen/e731f6f6e30a4c01f6bc7cdaa389d463 to your computer and use it in GitHub Desktop.
Save Saghen/e731f6f6e30a4c01f6bc7cdaa389d463 to your computer and use it in GitHub Desktop.
blink.cmp vs nvim-cmp
{
'hrsh7th/nvim-cmp',
dependencies = {
'hrsh7th/cmp-nvim-lsp',
'hrsh7th/cmp-nvim-lsp-signature-help',
'f3fora/cmp-spell',
'L3MON4D3/LuaSnip',
'rafamadriz/friendly-snippets',
},
config = function()
local cmp = require('nvim-cmp')
cmp.setup({
experimental = { ghost_text = true },
completion = {
completeopt = 'menu,menuone,noinsert'
},
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = {
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.confirm({
behavior = cmp.ConfirmBehavior.Insert,
select = true,
})
else
fallback()
end
end),
["<CR>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.confirm({
behavior = cmp.ConfirmBehavior.Insert,
select = true,
})
else
fallback()
end
end),
["<C-n>"] = cmp.mapping({
c = function()
if cmp.visible() then
cmp.select_next_item({behavior = cmp.SelectBehavior.Select })
else
vim.api.nvim_feedkeys(t("<Down>"), "n", true)
end
end,
i = function(fallback)
if cmp.visible() then
cmp.select_next_item({behavior = cmp.SelectBehavior.Select })
else
fallback()
end
end,
}),
["<C-p>"] = cmp.mapping({
c = function()
if cmp.visible() then
cmp.select_prev_item({behavior = cmp.SelectBehavior.Select })
else
vim.api.nvim_feedkeys(t("<Up>"), "n", true)
end
end,
i = function(fallback)
if cmp.visible() then
cmp.select_prev_item({behavior = cmp.SelectBehavior.Select })
else
fallback()
end
end,
}),
},
formatting = {
fields = { "kind", "abbr", "menu" },
format = function(entry, vim_item)
local kind = lspkind.cmp_format({ preset = "codicons", 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,
},
sources = {
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "spell" },
{ name = "nvim_lsp_signature_help" },
},
window = {
completion = {
winhighlight = "Normal:Pmenu,FloatBorder:FloatBorder,CursorLine:Visual,Search:None",
col_offset = -3,
side_padding = 0,
},
documentation = {
border = "rounded",
side_padding = 2,
winhighlight = "Normal:CmpDocumentation,FloatBorder:CmpDocumentationBorder,CursorLine:Visual,Search:None",
},
},
})
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment