How to limit responses until n characters are typed? #2019
-
Here's my configuration as it is. I'm wondering how I can tweak the suggestions so that they don't pop up e.g. the moment I break a new line, which gets quite annoying in a context that IMO doesn't require completion. local lsp = require("lsp-zero")
local cmp = require("cmp")
local luasnip = require("luasnip")
local cmp_autopairs = require("nvim-autopairs.completion.cmp")
local cmp_context = require("cmp.config.context")
local mode_information = vim.api.nvim_get_mode()
local acceptCompletion = cmp.mapping({
i = function(fallback)
if cmp.visible() then
cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true })
else
fallback()
end
end,
s = cmp.mapping.confirm({ select = true }),
c = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }),
})
lsp.extend_cmp()
cmp.setup({
enabled = function()
if mode_information.mode == "c" then
return true
end
return not cmp_context.in_treesitter_capture("comment")
and not cmp_context.in_syntax_group("Comment")
end,
experimental = {
ghost_text = true,
},
formatting = lsp.cmp_format({ details = true }),
mapping = cmp.mapping.preset.insert({
["<C-Space>"] = cmp.mapping.complete(),
["<Tab>"] = acceptCompletion,
["<CR>"] = acceptCompletion,
["<Esc>"] = cmp.mapping.abort(),
["<Up>"] = cmp.mapping.select_prev_item({ behavior = "select" }),
["<Down>"] = cmp.mapping.select_next_item({ behavior = "select" }),
}),
snippets = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
sources = cmp.config.sources({
{ name = "path" },
{
name = "nvim_lsp",
entry_filter = function(entry)
return cmp.lsp.CompletionItemKind.Text ~= entry:get_kind()
end,
},
{ name = "luasnip" },
{
name = "lazydev",
},
{ name = "cmp_tabnine", group_index = 0 },
}, {
{ name = "buffer" },
{
name = "cmdline",
option = {
ignore_cmds = { "Man", "!" },
},
},
}),
})
cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done()) SN: Apologies for the goliath post, only leaving it here for brevity in case something I've added needs to be addressed to achieve this. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I don't think newline cause completion to be triggered To limit completion until a certain character is typed, you can use the cmp.setup({
completion = {
keyword_length = 3,
},
}) |
Beta Was this translation helpful? Give feedback.
I don't think newline cause completion to be triggered
To limit completion until a certain character is typed, you can use the
completion.keyword_length
config