Skip to content

Commit c932e29

Browse files
saghenvantmet
authored andcommitted
feat: switch nvim-cmp for blink.cmp (nvim-lua#1426)
1 parent 2a6cb78 commit c932e29

File tree

2 files changed

+73
-101
lines changed

2 files changed

+73
-101
lines changed

init.lua

Lines changed: 72 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,8 @@ require('lazy').setup({
488488
-- Useful status updates for LSP.
489489
{ 'j-hui/fidget.nvim', opts = {} },
490490

491-
-- Allows extra capabilities provided by nvim-cmp
492-
'hrsh7th/cmp-nvim-lsp',
491+
-- Allows extra capabilities provided by blink.cmp
492+
'saghen/blink.cmp',
493493
},
494494
config = function()
495495
-- Brief aside: **What is LSP?**
@@ -656,10 +656,9 @@ require('lazy').setup({
656656

657657
-- LSP servers and clients are able to communicate to each other what features they support.
658658
-- By default, Neovim doesn't support everything that is in the LSP specification.
659-
-- When you add nvim-cmp, luasnip, etc. Neovim now has *more* capabilities.
660-
-- So, we create new capabilities with nvim cmp, and then broadcast that to the servers.
661-
local capabilities = vim.lsp.protocol.make_client_capabilities()
662-
capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities())
659+
-- When you add blink.cmp, luasnip, etc. Neovim now has *more* capabilities.
660+
-- So, we create new capabilities with blink.cmp, and then broadcast that to the servers.
661+
local capabilities = require('blink.cmp').get_lsp_capabilities()
663662

664663
-- Enable the following language servers
665664
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
@@ -785,12 +784,14 @@ require('lazy').setup({
785784
},
786785

787786
{ -- Autocompletion
788-
'hrsh7th/nvim-cmp',
789-
event = 'InsertEnter',
787+
'saghen/blink.cmp',
788+
event = 'VimEnter',
789+
version = '1.*',
790790
dependencies = {
791-
-- Snippet Engine & its associated nvim-cmp source
791+
-- Snippet Engine
792792
{
793793
'L3MON4D3/LuaSnip',
794+
version = '2.*',
794795
build = (function()
795796
-- Build Step is needed for regex support in snippets.
796797
-- This step is not supported in many windows environments.
@@ -811,95 +812,74 @@ require('lazy').setup({
811812
-- end,
812813
-- },
813814
},
815+
opts = {},
814816
},
815-
'saadparwaiz1/cmp_luasnip',
816-
817-
-- Adds other completion capabilities.
818-
-- nvim-cmp does not ship with all sources by default. They are split
819-
-- into multiple repos for maintenance purposes.
820-
'hrsh7th/cmp-nvim-lsp',
821-
'hrsh7th/cmp-path',
822-
'hrsh7th/cmp-nvim-lsp-signature-help',
817+
'folke/lazydev.nvim',
823818
},
824-
config = function()
825-
-- See `:help cmp`
826-
local cmp = require 'cmp'
827-
local luasnip = require 'luasnip'
828-
luasnip.config.setup {}
829-
830-
cmp.setup {
831-
snippet = {
832-
expand = function(args)
833-
luasnip.lsp_expand(args.body)
834-
end,
835-
},
836-
completion = { completeopt = 'menu,menuone,noinsert' },
837-
838-
-- For an understanding of why these mappings were
839-
-- chosen, you will need to read `:help ins-completion`
819+
--- @module 'blink.cmp'
820+
--- @type blink.cmp.Config
821+
opts = {
822+
keymap = {
823+
-- 'default' (recommended) for mappings similar to built-in completions
824+
-- <c-y> to accept ([y]es) the completion.
825+
-- This will auto-import if your LSP supports it.
826+
-- This will expand snippets if the LSP sent a snippet.
827+
-- 'super-tab' for tab to accept
828+
-- 'enter' for enter to accept
829+
-- 'none' for no mappings
830+
--
831+
-- For an understanding of why the 'default' preset is recommended,
832+
-- you will need to read `:help ins-completion`
840833
--
841834
-- No, but seriously. Please read `:help ins-completion`, it is really good!
842-
mapping = cmp.mapping.preset.insert {
843-
-- Select the [n]ext item
844-
['<C-n>'] = cmp.mapping.select_next_item(),
845-
-- Select the [p]revious item
846-
['<C-p>'] = cmp.mapping.select_prev_item(),
847-
848-
-- Scroll the documentation window [b]ack / [f]orward
849-
['<C-b>'] = cmp.mapping.scroll_docs(-4),
850-
['<C-f>'] = cmp.mapping.scroll_docs(4),
851-
852-
-- Accept ([y]es) the completion.
853-
-- This will auto-import if your LSP supports it.
854-
-- This will expand snippets if the LSP sent a snippet.
855-
['<C-y>'] = cmp.mapping.confirm { select = true },
856-
857-
-- If you prefer more traditional completion keymaps,
858-
-- you can uncomment the following lines
859-
--['<CR>'] = cmp.mapping.confirm { select = true },
860-
--['<Tab>'] = cmp.mapping.select_next_item(),
861-
--['<S-Tab>'] = cmp.mapping.select_prev_item(),
862-
863-
-- Manually trigger a completion from nvim-cmp.
864-
-- Generally you don't need this, because nvim-cmp will display
865-
-- completions whenever it has completion options available.
866-
['<C-Space>'] = cmp.mapping.complete {},
867-
868-
-- Think of <c-l> as moving to the right of your snippet expansion.
869-
-- So if you have a snippet that's like:
870-
-- function $name($args)
871-
-- $body
872-
-- end
873-
--
874-
-- <c-l> will move you to the right of each of the expansion locations.
875-
-- <c-h> is similar, except moving you backwards.
876-
['<C-l>'] = cmp.mapping(function()
877-
if luasnip.expand_or_locally_jumpable() then
878-
luasnip.expand_or_jump()
879-
end
880-
end, { 'i', 's' }),
881-
['<C-h>'] = cmp.mapping(function()
882-
if luasnip.locally_jumpable(-1) then
883-
luasnip.jump(-1)
884-
end
885-
end, { 'i', 's' }),
835+
--
836+
-- All presets have the following mappings:
837+
-- <tab>/<s-tab>: move to right/left of your snippet expansion
838+
-- <c-space>: Open menu or open docs if already open
839+
-- <c-n>/<c-p> or <up>/<down>: Select next/previous item
840+
-- <c-e>: Hide menu
841+
-- <c-k>: Toggle signature help
842+
--
843+
-- See :h blink-cmp-config-keymap for defining your own keymap
844+
preset = 'default',
886845

887-
-- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see:
888-
-- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps
889-
},
890-
sources = {
891-
{
892-
name = 'lazydev',
893-
-- set group index to 0 to skip loading LuaLS completions as lazydev recommends it
894-
group_index = 0,
895-
},
896-
{ name = 'nvim_lsp' },
897-
{ name = 'luasnip' },
898-
{ name = 'path' },
899-
{ name = 'nvim_lsp_signature_help' },
846+
-- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see:
847+
-- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps
848+
},
849+
850+
appearance = {
851+
-- 'mono' (default) for 'Nerd Font Mono' or 'normal' for 'Nerd Font'
852+
-- Adjusts spacing to ensure icons are aligned
853+
nerd_font_variant = 'mono',
854+
},
855+
856+
completion = {
857+
-- By default, you may press `<c-space>` to show the documentation.
858+
-- Optionally, set `auto_show = true` to show the documentation after a delay.
859+
documentation = { auto_show = false, auto_show_delay_ms = 500 },
860+
},
861+
862+
sources = {
863+
default = { 'lsp', 'path', 'snippets', 'lazydev' },
864+
providers = {
865+
lazydev = { module = 'lazydev.integrations.blink', score_offset = 100 },
900866
},
901-
}
902-
end,
867+
},
868+
869+
snippets = { preset = 'luasnip' },
870+
871+
-- Blink.cmp includes an optional, recommended rust fuzzy matcher,
872+
-- which automatically downloads a prebuilt binary when enabled.
873+
--
874+
-- By default, we use the Lua implementation instead, but you may enable
875+
-- the rust implementation via `'prefer_rust_with_warning'`
876+
--
877+
-- See :h blink-cmp-config-fuzzy for more information
878+
fuzzy = { implementation = 'lua' },
879+
880+
-- Shows a signature help window while you type arguments for a function
881+
signature = { enabled = true },
882+
},
903883
},
904884

905885
{ -- You can easily change to a different colorscheme.

lua/kickstart/plugins/autopairs.lua

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,5 @@
44
return {
55
'windwp/nvim-autopairs',
66
event = 'InsertEnter',
7-
-- Optional dependency
8-
dependencies = { 'hrsh7th/nvim-cmp' },
9-
config = function()
10-
require('nvim-autopairs').setup {}
11-
-- If you want to automatically add `(` after selecting a function or method
12-
local cmp_autopairs = require 'nvim-autopairs.completion.cmp'
13-
local cmp = require 'cmp'
14-
cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done())
15-
end,
7+
opts = {},
168
}

0 commit comments

Comments
 (0)