Skip to content

Instantly share code, notes, and snippets.

@mhartington
Created March 30, 2025 23:43
Show Gist options
  • Save mhartington/d2e757e1cdb2ed678ee755de640050a0 to your computer and use it in GitHub Desktop.
Save mhartington/d2e757e1cdb2ed678ee755de640050a0 to your computer and use it in GitHub Desktop.
blink vs 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",
},
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment