Replies: 5 comments 3 replies
-
In the same vein, I'm trying to have both TAB and CR snippets from the wiki working together. TAB works but not CR when I specifically select something. Not sure why: {
'hrsh7th/nvim-cmp',
config = function()
local cmp = require("cmp")
cmp.setup({
mapping = {
-- If nothing is selected (including preselections) add a newline as usual.
-- If something has explicitly been selected by the user, select it.
["<Enter>"] = cmp.mapping({
i = function(fallback)
if cmp.visible() and cmp.get_active_entry() then
cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false })
else
fallback()
end
end,
s = cmp.mapping.confirm({ select = true }),
c = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }),
}),
["<Tab>"] = cmp.mapping(function(fallback)
-- This little snippet will confirm with tab, and if no entry is selected, will confirm the first item
if cmp.visible() then
local entry = cmp.get_selected_entry()
if not entry then
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
else
cmp.confirm()
end
else
fallback()
end
end, { "i", "s", "c", }),
}
})
end
}, |
Beta Was this translation helpful? Give feedback.
-
It seems that your completion = {
completeopt = "menu,menuone,noinsert,noselect",
}, To avoid auto selection. |
Beta Was this translation helpful? Give feedback.
-
Late comment, but try my config ["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
local entries = cmp.get_entries()
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
if #entries == 1 then
cmp.confirm()
end
else
fallback()
end
end, { "i", "s" }),
|
Beta Was this translation helpful? Give feedback.
-
I was googling how to tab complete with nvim-cmp and got here. Both of these tab completions are amazing. |
Beta Was this translation helpful? Give feedback.
-
it do not work when I use the same config from @twiddli. return {
{
"L3MON4D3/LuaSnip",
keys = function()
return {}
end,
},
{
"hrsh7th/nvim-cmp",
opts = function()
local cmp = require("cmp")
cmp.setup({
mapping = {
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
local entry = cmp.get_selected_entry()
if not entry then
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
else
cmp.confirm()
end
else
fallback()
end
end, { "i", "s", "c" }),
},
})
end,
},
} I dont know the diff of 'config' and 'opts', but thanks this issue and guys. |
Beta Was this translation helpful? Give feedback.
-
Using the following, from LazyVim example:
I guess i'm expecting for completion options to only appear after pressing
<TAB>
, but this does not seem to be the case.If I create the following file
test.py
;After entering the number
2
and press<RETURN>
, i get a big blob of bsd license.It looks like when I press
2
the completion window automatically pops up with the first bsd license completion option selected, and when I press<RETURN>
it selects it.How can i make it so completion pop up window only appear on
<TAB>
?( there is a very high possibility i'm doing something wrong )
Beta Was this translation helpful? Give feedback.
All reactions