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
+43 -61
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, else
select = true, fallback()
} end
) end,
else ["<C-x><C-o>"] = cmp.mapping.complete(),
fallback() ["<C-l>"] = function (fallback)
end if luasnip.expand_or_locally_jumpable() then
end, { "i", "s", } luasnip.expand_or_jump()
), else
["<Tab>"] = cmp.mapping( fallback()
function (fallback) end
if cmp.visible() and not has_words_after() then end,
cmp.select_next_item() ["<C-h>"] = function (fallback)
-- elseif luasnip.expand_or_jumpable() then if luasnip.locally_jumpable(-1) then
-- luasnip.expand_or_jump() luasnip.jump(-1)
elseif has_words_before() then else
cmp.complete() fallback()
else end
fallback() end,
end ["<C-b>"] = function (fallback)
end, { "i", "s", } if cmp.visible_docs() then
), cmp.scroll_docs(-4)
["<S-Tab>"] = cmp.mapping( else
function (fallback) fallback()
if cmp.visible() and not has_words_after() then end
cmp.select_prev_item() end,
elseif luasnip.jumpable(-1) then ["<C-f>"] = function (fallback)
luasnip.jump(-1) if cmp.visible_docs() then
else cmp.scroll_docs(4)
fallback() else
end fallback()
end, { "i", "s", } end
), end,
}, },
sources = { sources = {
{ name = "nvim_lsp", }, { name = "nvim_lsp", },