Skip to content

Commit 2be82cb

Browse files
saghenkmha915
authored andcommitted
feat: switch nvim-cmp for blink.cmp (nvim-lua#1426)
1 parent 26b295f commit 2be82cb

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
@@ -485,8 +485,8 @@ require('lazy').setup({
485485
-- Useful status updates for LSP.
486486
{ 'j-hui/fidget.nvim', opts = {} },
487487

488-
-- Allows extra capabilities provided by nvim-cmp
489-
'hrsh7th/cmp-nvim-lsp',
488+
-- Allows extra capabilities provided by blink.cmp
489+
'saghen/blink.cmp',
490490
},
491491
config = function()
492492
-- Brief aside: **What is LSP?**
@@ -653,10 +653,9 @@ require('lazy').setup({
653653

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

661660
-- Enable the following language servers
662661
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
@@ -775,12 +774,14 @@ require('lazy').setup({
775774
},
776775

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

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

895875
{ -- 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)