Closed otavioschwanck closed 2 years ago
Which key do you press to expand the snippet? Right now, jumping to the next placeholder only works if the snippet was already expanded (the item was selected from cmp's menu). The default in cmp is <cr>
by the way.
For example, I have this mapping:
["<C-f>"] = cmp.mapping(
cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
{ "i", "s" }
),
I am having a similar issue, potentially the same. I am using return to expand snippets, and also set tab and s-tab to jump forward and backward like mentioned above. After expended a snippet, the cursor jumps to the first placeholder in select mode waiting for user input.
@Guzzii could you share your nvim-cmp
config? It might be a configuration issue because I can't reproduce it (<Tab>
moves me to the next placeholder even in select mode).
Sure, below is my config
vim.cmd('set completeopt=menu,menuone,noselect')
local cmp = require('cmp')
local lspkind = require('lspkind')
local cmp_ultisnips_mappings = require('cmp_nvim_ultisnips.mappings')
cmp.setup({
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
vim.fn['UltiSnips#Anon'](args.body) -- For `ultisnips` users.
end,
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' }, { name = 'ultisnips' },
{ name = 'buffer' }, { name = 'nvim_lua' },
{ name = 'tmux' }, { name = 'emoji' }
}),
mapping = {
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
['<C-e>'] = cmp.mapping({ i = cmp.mapping.abort(), c = cmp.mapping.close(), }),
['<CR>'] = cmp.mapping.confirm({ select = false }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
['<Tab>'] = cmp.mapping(
function(fallback)
cmp_ultisnips_mappings.compose {'select_next_item', 'jump_forwards'}(fallback)
end, {'i', 's'}
),
['<S-Tab>'] = cmp.mapping(
function(fallback)
cmp_ultisnips_mappings.compose {'select_prev_item', 'jump_backwards'}(fallback)
end, {'i', 's'}
),
['<Down>'] = cmp.mapping(cmp.mapping.select_next_item(), {'i', 's', 'c'}),
['<Up>'] = cmp.mapping(cmp.mapping.select_prev_item(), {'i', 's', 'c'}),
},
formatting = {
format = lspkind.cmp_format({
with_text = true,
menu = {
buffer = '[Buffer]',
nvim_lsp = '[LSP]',
nvim_lua = '[Lua]',
ultisnips = '[UltraSnip]',
tmux = '[Tmux]',
emoji = '[Emoji]',
}
}),
},
})
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline('/', { sources = {{ name = 'buffer' }}})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
sources = cmp.config.sources({{ name = 'path' }}, {{ name = 'cmdline' }})
})
Sorry, I still can't reproduce it with your config. For some reason, setting <cr>
as the key to confirm the selected item does not even work for me (it does not expand the snippet). Can you check that smap <Plug>
contains the three mappings cmpu-expand
, cmpu-jump-forwards
and cmpu-jump-backwards
?
Just to confirm, with the latest update, it is working as expected and no longer an issue.
Perfect, thanks for letting me know!
My config:
I dont want tab to move forward / backwards on autocomplete list (i use C-n and C-p for this). Tab is just for snippets.