Skip to content

Commit b49d14c

Browse files
SaghenThanh Danh
authored andcommitted
feat: switch nvim-cmp for blink.cmp (nvim-lua#1426)
1 parent f25eb13 commit b49d14c

File tree

2 files changed

+42
-77
lines changed

2 files changed

+42
-77
lines changed

init.lua

Lines changed: 41 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -650,12 +650,8 @@ require('lazy').setup({ -- NOTE: Plugins can be added with a link (or for a gith
650650
-- Useful status updates for LSP.
651651
{ 'j-hui/fidget.nvim', opts = {} },
652652

653-
-- Allows extra capabilities provided by nvim-cmp
654-
'hrsh7th/cmp-nvim-lsp',
655-
-- {
656-
-- 'folke/neodev.nvim',
657-
-- opts = {},
658-
-- },
653+
-- Allows extra capabilities provided by blink.cmp
654+
'saghen/blink.cmp',
659655
},
660656
config = function()
661657
-- Brief aside: **What is LSP?**
@@ -822,10 +818,9 @@ require('lazy').setup({ -- NOTE: Plugins can be added with a link (or for a gith
822818

823819
-- LSP servers and clients are able to communicate to each other what features they support.
824820
-- By default, Neovim doesn't support everything that is in the LSP specification.
825-
-- When you add nvim-cmp, luasnip, etc. Neovim now has *more* capabilities.
826-
-- So, we create new capabilities with nvim cmp, and then broadcast that to the servers.
827-
local capabilities = vim.lsp.protocol.make_client_capabilities()
828-
capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities())
821+
-- When you add blink.cmp, luasnip, etc. Neovim now has *more* capabilities.
822+
-- So, we create new capabilities with blink.cmp, and then broadcast that to the servers.
823+
local capabilities = require('blink.cmp').get_lsp_capabilities()
829824

830825
-- Enable the following language servers
831826
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
@@ -1009,11 +1004,14 @@ require('lazy').setup({ -- NOTE: Plugins can be added with a link (or for a gith
10091004
},
10101005
},
10111006
{ -- Autocompletion
1012-
'hrsh7th/nvim-cmp',
1013-
event = 'InsertEnter',
1014-
dependencies = { -- Snippet Engine & its associated nvim-cmp source
1007+
'saghen/blink.cmp',
1008+
event = 'VimEnter',
1009+
version = '1.*',
1010+
dependencies = {
1011+
-- Snippet Engine
10151012
{
10161013
'L3MON4D3/LuaSnip',
1014+
version = '2.*',
10171015
build = (function()
10181016
-- Build Step is needed for regex support in snippets.
10191017
-- This step is not supported in many windows environments.
@@ -1034,39 +1032,36 @@ require('lazy').setup({ -- NOTE: Plugins can be added with a link (or for a gith
10341032
end,
10351033
},
10361034
},
1035+
opts = {},
10371036
},
1038-
'saadparwaiz1/cmp_luasnip', -- Adds other completion capabilities.
1039-
-- nvim-cmp does not ship with all sources by default. They are split
1040-
-- into multiple repos for maintenance purposes.
1041-
'hrsh7th/cmp-nvim-lsp',
1042-
'hrsh7th/cmp-path',
1043-
'hrsh7th/cmp-nvim-lsp-signature-help',
1037+
'folke/lazydev.nvim',
10441038
},
1045-
config = function()
1046-
-- See `:help cmp`
1047-
local cmp = require 'cmp'
1048-
local luasnip = require 'luasnip'
1049-
luasnip.config.setup {}
1050-
1051-
cmp.setup {
1052-
snippet = {
1053-
expand = function(args)
1054-
luasnip.lsp_expand(args.body)
1055-
end,
1056-
},
1057-
completion = {
1058-
completeopt = 'menu,menuone,noinsert',
1059-
},
1060-
1061-
-- For an understanding of why these mappings were
1062-
-- chosen, you will need to read `:help ins-completion`
1039+
--- @module 'blink.cmp'
1040+
--- @type blink.cmp.Config
1041+
opts = {
1042+
keymap = {
1043+
-- 'default' (recommended) for mappings similar to built-in completions
1044+
-- <c-y> to accept ([y]es) the completion.
1045+
-- This will auto-import if your LSP supports it.
1046+
-- This will expand snippets if the LSP sent a snippet.
1047+
-- 'super-tab' for tab to accept
1048+
-- 'enter' for enter to accept
1049+
-- 'none' for no mappings
1050+
--
1051+
-- For an understanding of why the 'default' preset is recommended,
1052+
-- you will need to read `:help ins-completion`
10631053
--
10641054
-- No, but seriously. Please read `:help ins-completion`, it is really good!
1065-
mapping = cmp.mapping.preset.insert {
1066-
-- Select the [n]ext item
1067-
['<C-n>'] = cmp.mapping.select_next_item(),
1068-
-- Select the [p]revious item
1069-
['<C-p>'] = cmp.mapping.select_prev_item(),
1055+
--
1056+
-- All presets have the following mappings:
1057+
-- <tab>/<s-tab>: move to right/left of your snippet expansion
1058+
-- <c-space>: Open menu or open docs if already open
1059+
-- <c-n>/<c-p> or <up>/<down>: Select next/previous item
1060+
-- <c-e>: Hide menu
1061+
-- <c-k>: Toggle signature help
1062+
--
1063+
-- See :h blink-cmp-config-keymap for defining your own keymap
1064+
preset = 'default',
10701065

10711066
-- Scroll the documentation window [b]ack / [f]orward
10721067
['<C-d>'] = cmp.mapping.scroll_docs(-4),
@@ -1083,32 +1078,10 @@ require('lazy').setup({ -- NOTE: Plugins can be added with a link (or for a gith
10831078
select = true,
10841079
},
10851080

1086-
-- Manually trigger a completion from nvim-cmp.
1087-
-- Generally you don't need this, because nvim-cmp will display
1088-
-- completions whenever it has completion options available.
1089-
['<C-Space>'] = cmp.mapping.complete {},
1090-
1091-
-- Think of <c-l> as moving to the right of your snippet expansion.
1092-
-- So if you have a snippet that's like:
1093-
-- function $name($args)
1094-
-- $body
1095-
-- end
1096-
--
1097-
-- <c-l> will move you to the right of each of the expansion locations.
1098-
-- <c-h> is similar, except moving you backwards.
1099-
['<C-l>'] = cmp.mapping(function()
1100-
if luasnip.expand_or_locally_jumpable() then
1101-
luasnip.expand_or_jump()
1102-
end
1103-
end, { 'i', 's' }),
1104-
['<C-h>'] = cmp.mapping(function()
1105-
if luasnip.locally_jumpable(-1) then
1106-
luasnip.jump(-1)
1107-
end
1108-
end, { 'i', 's' }),
1109-
1110-
-- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see:
1111-
-- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps
1081+
sources = {
1082+
default = { 'lsp', 'path', 'snippets', 'lazydev' },
1083+
providers = {
1084+
lazydev = { module = 'lazydev.integrations.blink', score_offset = 100 },
11121085
},
11131086
sources = {
11141087
{

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)