change nvim-cmp to blink.cmp

This commit is contained in:
xesc 2025-06-29 13:51:25 +02:00
parent cf67d20daa
commit 091a472949
4 changed files with 162 additions and 153 deletions

View file

@ -76,3 +76,4 @@ vim.opt.shortmess = "aItTF"
-- hide buffers instead of closing
vim.opt.hidden = true
vim.opt.winborder = 'rounded'

152
lua/plugin/cmp.lua Normal file
View file

@ -0,0 +1,152 @@
return {
"saghen/blink.cmp",
build = 'cargo +nightly build --release',
dependencies = {
{ "L3MON4D3/LuaSnip", version = "v2.*" }
},
lazy = true,
opts = {
snippets = { preset = 'luasnip' },
sources = {
default = { 'buffer', 'lsp', 'path', 'snippets' },
},
fuzzy = { implementation = 'prefer_rust' },
appearance = {
nerd_font_variant = 'mono',
kind_icons = {
Text = "",
Method = "󰆧",
Function = "󰊕",
Constructor = "",
Field = "󰇽",
Variable = "󰂡",
Class = "󰠱",
Interface = "",
Module = "",
Property = "󰜢",
Unit = "",
Value = "󰎠",
Enum = "",
Keyword = "󰌋",
Snippet = "",
Color = "󰏘",
File = "󰈙",
Reference = "",
Folder = "󰉋",
EnumMember = "",
Constant = "󰏿",
Struct = "",
Event = "",
Operator = "󰆕",
TypeParameter = "󰅲"
}
},
completion = {
keyword = {
range = 'full'
},
ghost_text = {
enabled = true
},
menu = {
winhighlight = 'Normal:NormalFloat,FloatBorder:FloatBorder,CursorLine:CursorLine,Search:None',
min_width = 40,
max_height = 25,
draw = {
columns = { { 'label', 'label_description', gap = 1 }, { 'kind_icon', 'kind', gap = 1 } },
components = {
label = {
highlight = function(ctx)
-- label and label details
local highlights = {
{ 0, #ctx.label, group = ctx.deprecated and 'DiagnosticFloatingWarn' or 'NormalFloator' },
}
if ctx.label_detail then
table.insert(highlights, { #ctx.label, #ctx.label + #ctx.label_detail, group = 'NormalFloat' })
end
return highlights
end,
},
}
}
},
documentation = {
auto_show = true,
auto_show_delay_ms = 0,
window = {
winhighlight = 'Normal:NormalFloat,FloatBorder:FloatBorder,CursorLine:CursorLine',
}
},
},
keymap = {
['<C-n>'] = { 'hide', 'show', 'fallback' },
['<CR>'] = { 'accept', 'fallback' },
['<Tab>'] = {
function(cmp)
if cmp.snippet_active() then
return cmp.accept()
else
return cmp.select_next()
end
end,
'snippet_forward',
'fallback'
},
['<S-Tab>'] = {
function(cmp)
if cmp.snippet_active() then
return cmp.accept()
else
return cmp.select_prev()
end
end,
'snippet_backward',
'fallback'
},
['<C-k>'] = { 'select_prev', 'fallback' },
['<C-j>'] = { 'select_next', 'fallback' },
['<C-u>'] = { 'scroll_documentation_up', 'fallback' },
['<C-d>'] = { 'scroll_documentation_down', 'fallback' },
['<C-s>'] = { 'show_signature', 'hide_signature', 'fallback' },
},
signature = {
enabled = true,
window = {
winhighlight = 'Normal:NormalFloat,FloatBorder:FloatBorder',
}
},
cmdline = {
keymap = { preset = 'inherit', ['<cr>'] = { 'accept_and_enter', 'fallback' } },
completion = {
menu = {
auto_show = function()
local type = vim.fn.getcmdtype()
-- Search forward and backward
if type == "/" or type == "?" then
return false
end
-- Commands
if type == ":" then
return true
end
return false
end,
}
},
sources = function()
local type = vim.fn.getcmdtype()
-- Search forward and backward
if type == "/" or type == "?" then
return { "buffer" }
end
-- Commands
if type == ":" then
return { "cmdline" }
end
return {}
end,
},
}
}

View file

@ -4,13 +4,7 @@ return {
dependencies = {
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline",
"hrsh7th/nvim-cmp",
"L3MON4D3/LuaSnip",
"saadparwaiz1/cmp_luasnip",
"saghen/blink.cmp",
"nvim-telescope/telescope-ui-select.nvim",
"nvimtools/none-ls.nvim",
'nvim-treesitter/nvim-treesitter',
@ -18,147 +12,10 @@ return {
"jay-babu/mason-null-ls.nvim",
},
config = function()
-- autocomplete --
local kind_icons = {
Text = "",
Method = "󰆧",
Function = "󰊕",
Constructor = "",
Field = "󰇽",
Variable = "󰂡",
Class = "󰠱",
Interface = "",
Module = "",
Property = "󰜢",
Unit = "",
Value = "󰎠",
Enum = "",
Keyword = "󰌋",
Snippet = "",
Color = "󰏘",
File = "󰈙",
Reference = "",
Folder = "󰉋",
EnumMember = "",
Constant = "󰏿",
Struct = "",
Event = "",
Operator = "󰆕",
TypeParameter = "󰅲"
}
local has_words_before = function()
unpack = unpack or table.unpack
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and
vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
local luasnip = require("luasnip")
local cmp = require("cmp")
cmp.setup({
formatting = {
format = function(entry, vim_item)
-- Kind icons
vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind
-- Source
vim_item.menu = ({
buffer = "",
nvim_lsp = "",
luasnip = "",
nvim_lua = "",
latex_symbols = "",
})[entry.source.name]
return vim_item
end
},
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-e>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.abort()
else
cmp.complete()
end
end),
['<CR>'] = cmp.mapping.confirm({ select = false }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
-- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable()
-- they way you will only jump inside the snippet region
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'luasnip' }, -- For luasnip users.
{
name = 'buffer',
option = {
get_bufnrs = function()
return vim.api.nvim_list_bufs()
end
},
},
}, {
}),
-- Set configuration for specific filetype.
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline({ '/', '?' }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' }
}
}),
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
})
-- setup --
local client_capabilities = vim.lsp.protocol.make_client_capabilities()
local cmp_capabilities = require('cmp_nvim_lsp').default_capabilities()
local capabilities = vim.tbl_deep_extend(
"force",
client_capabilities,
cmp_capabilities
)
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = vim.tbl_deep_extend('force', capabilities, require('blink.cmp').get_lsp_capabilities({}, false))
-- mason --
@ -255,7 +112,6 @@ return {
prefix = '', -- Could be '●', '■', 'x', '▎', or anything else
},
})
end,
}
}

View file

@ -22,12 +22,12 @@ return {
path = "~/notes",
},
},
completion = {
-- Set to false to disable completion.
nvim_cmp = true,
-- Trigger completion at 2 chars.
min_chars = 1,
},
-- completion = {
-- -- Set to false to disable completion.
-- nvim_cmp = true,
-- -- Trigger completion at 2 chars.
-- min_chars = 1,
-- },
mappings = {
-- Overrides the 'gf' mapping to work on markdown/wiki links within your vault.