how to use tab for both select_next snippet_forward based on condition. #628
Unanswered
AlixShahid
asked this question in
Q&A
Replies: 2 comments 1 reply
-
keymap = {
preset = "none",
["<Tab>"] = { "select_next", "snippet_forward", "fallback", },
["<S-Tab>"] = { "select_prev", "snippet_backward", "fallback", },
["<Enter>"] = { "accept", "fallback", },
["<C- >"] = { "show", "hide", },
["<C-d>"] = { "show_documentation", "hide_documentation", },
}, |
Beta Was this translation helpful? Give feedback.
1 reply
-
I have a function bound to tab which does this: local handle_tab = function(cmp)
-- if a snippet is running and there is no ghost text visible, snippet next
local snippet_visible = cmp.snippet_active()
local ghost_text_visible = cmp.is_ghost_text_visible()
if snippet_visible and ghost_text_visible == false then
return cmp.snippet_forward()
end
-- if there is ghost text but the menu is closed, open it with the ghost
-- text's entry preselected
local is_open = cmp.is_menu_visible()
if is_open == false and ghost_text_visible then
return cmp.show({
initial_selected_item_idx = 1,
})
end
if is_open then
-- assuming the menu is open, if no option has been explicitly selected,
-- select the first one
local is_explicitly_selected = require("blink.cmp.completion.list").is_explicitly_selected
if is_explicitly_selected == false then
vim.schedule(function()
return require("blink.cmp.completion.list").select(1)
end)
return true
else
-- finally, assuming the menu is open and an entry has been explicitly selected,
-- select the next entry
return cmp.select_next()
end
end
end |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
in simple term what would be the blink.cmp version of this nvim-cmp
Beta Was this translation helpful? Give feedback.
All reactions