Skip to content

Customize cmp Completion

AstroNvim comes with blink.cmp for powering completion out of the box. This page documents common configuration options such as custom keybindings or adding more sources, for more detailed information on configuring the plugin be sure to check out the extensive blink.cmp Documentation.

Customize Keybindings

Some overrides require access to the plugin itself that you are overriding. This comes up a lot in things adding custom mappings to blink.cmp. This can be achieved with the following plugin spec:

lua/plugins/blink.lua
return { -- override blink.cmp plugin
"Saghen/blink.cmp",
opts = {
keymap = {
["<Tab>"] = { "snippet_forward", "fallback" },
},
},
}

Customize Source Priority

Similarly to customizing mappings, you can customize and configure your blink.cmp providers as well:

lua/plugins/blink.lua
return { -- override blink.cmp plugin
"Saghen/blink.cmp",
opts = {
sources = {
providers = {
path = { score_offset = 3 },
lsp = { score_offset = 0 },
snippets = { score_offset = -1 },
buffer = { score_offset = -3 },
},
},
},
}

Modify Existing Source Options

You can use this blink.cmp override to also customize the options of the sources. You can find all of the available options for the providers in the blink.cmp Documentation:

lua/plugins/blink.lua
return { -- override blink.cmp plugin
"Saghen/blink.cmp",
opts = {
sources = {
providers = {
buffer = {
-- each provider can be customized with their `opts`
opts = {
get_bufnrs = function()
return vim.api.nvim_list_bufs()
end,
},
},
},
},
},
}

Add More Sources

To add more sources than the default, you can add the new blink source plugins (blink.cmp Community Sources) and configure the blink.cmp options to enable the provider:

lua/plugins/blink-emoji.lua
return {
"moyiz/blink-emoji.nvim",
lazy = true,
specs = {
{
"Saghen/blink.cmp",
optional = true,
opts = {
sources = {
-- enable the provider by default (automatically extends when merging tables)
default = { "emoji" },
providers = {
-- Specific details depend on the blink source
emoji = {
name = "Emoji",
module = "blink-emoji",
min_keyword_length = 1,
score_offset = -1,
},
},
},
},
},
},
}

Add nvim-cmp Sources

Not all sources for nvim-cmp are available as blink.cmp providers, but blink.cmp provides a compatibility layer to make it easy to add more sources. For more detail check out the blink.compat Documentation. Here is an example for adding cmp-latex-symbols:

lua/plugins/cmp-latex-symbols.lua
return {
"Saghen/blink.cmp",
optional = true,
dependencies = {
-- add the legacy cmp source as a dependency for `blink.cmp`
"kdheepak/cmp-latex-symbols",
},
specs = {
-- install the blink, nvim-cmp compatibility layer
{ "Saghen/blink.compat", version = "*", lazy = true, opts = {} },
},
opts = {
sources = {
-- enable the provider by default
default = { "latex" },
-- configure the provider for your new source
providers = {
latex = {
name = "latex_symbols",
module = "blink.compat.source",
score_offset = -1,
},
},
},
},
}