I have currently set tab to what is suggested by nvim-cmp:
mapping = {
-------other mappings --------
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
-------other mappings --------
}
This is sort of behavior I want but there is one problem.
Say I used a snippet which has multiple placeholders, I write in one of them and then exit insert mode and get into command mode. Now I do not change other place holders and want to insert a tab somewhere else in code, but nvim-cmp assumes(or seems to me atleast) that I am in snippet and would want to jump some characters, and tab will do that. But actually I want to insert actual tab character.
Behaviour I want:
A soon as I exit insert mode, it forgets all placeholder positions. Then I will be able to insert tab. According to me if I wanted to complete a snippet I could have done it in insert mode only.
Please hint to solution or provide required configuration.
I have been able to partially achieve this using (thanks to shaeinst):
mapping = {
-------other mappings --------
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump()
--elseif has_words_before() then
--cmp.complete()
else
fallback()
end
end, { "i", "s" }),
}
Using this, cursor only jumps to placeholders when I am inside snippet and also once I have covered all placeholders, it does not jump back. But still my requirement is that as soon as I exit insert mode, all the placeholders are neglected, but untill I am in insert mode I would like to even cycle through placeholders.