fix(cmp): use <C-n/p/y> keybinds instead of <Tab>

This commit is contained in:
2024-03-04 22:39:58 +01:00
parent 60e29c0fb4
commit 7dc4dae390
+33 -51
View File
@@ -25,27 +25,9 @@ local function setup()
local utils = require("utils") local utils = require("utils")
local cmp = require("cmp") local cmp = require("cmp")
local luasnip = require("luasnip") local luasnip = require("luasnip")
local lspkind = utils.try_require("lspkind", module_name)
local lspkind
utils.try_require("lspkind", module_name, function (module)
lspkind = module
end)
local opt = { local opt = {
enabled = function ()
local context = require "cmp.config.context"
if vim.api.nvim_get_mode().mode == "c" then
-- keep command mode completion enabled
return true
elseif context.in_treesitter_capture("comment") or
context.in_syntax_group("Comment") then
-- disable completion in comments
return false
else
-- enable only if cursor is at the end of a word
return has_words_before() and not has_words_after()
end
end,
preselect = cmp.PreselectMode.None, preselect = cmp.PreselectMode.None,
completion = { keyword_length = 0, }, completion = { keyword_length = 0, },
snippet = { snippet = {
@@ -72,48 +54,48 @@ local function setup()
}, },
experimental = { ghost_text = true, }, experimental = { ghost_text = true, },
mapping = { mapping = {
["<C-p>"] = cmp.mapping.select_prev_item(), ["<C-p>"] = cmp.mapping.select_prev_item({
["<C-n>"] = cmp.mapping.select_next_item(), behavior = cmp.SelectBehavior.Select,
["<C-d>"] = cmp.mapping.scroll_docs(-4), }),
["<C-f>"] = cmp.mapping.scroll_docs(4), ["<C-n>"] = cmp.mapping.select_next_item({
["<CR>"] = cmp.mapping( behavior = cmp.SelectBehavior.Select,
function (fallback) }),
if cmp.visible() and cmp.get_selected_entry() then ["<C-y>"] = function (fallback)
cmp.confirm( if cmp.visible() then
{ cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, })
behavior = cmp.ConfirmBehavior.Replace,
select = true,
}
)
else else
fallback() fallback()
end end
end, { "i", "s", } end,
), ["<C-x><C-o>"] = cmp.mapping.complete(),
["<Tab>"] = cmp.mapping( ["<C-l>"] = function (fallback)
function (fallback) if luasnip.expand_or_locally_jumpable() then
if cmp.visible() and not has_words_after() then luasnip.expand_or_jump()
cmp.select_next_item()
-- elseif luasnip.expand_or_jumpable() then
-- luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else else
fallback() fallback()
end end
end, { "i", "s", } end,
), ["<C-h>"] = function (fallback)
["<S-Tab>"] = cmp.mapping( if luasnip.locally_jumpable(-1) then
function (fallback)
if cmp.visible() and not has_words_after() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1) luasnip.jump(-1)
else else
fallback() fallback()
end end
end, { "i", "s", } end,
), ["<C-b>"] = function (fallback)
if cmp.visible_docs() then
cmp.scroll_docs(-4)
else
fallback()
end
end,
["<C-f>"] = function (fallback)
if cmp.visible_docs() then
cmp.scroll_docs(4)
else
fallback()
end
end,
}, },
sources = { sources = {
{ name = "nvim_lsp", }, { name = "nvim_lsp", },