jump to next tabstop without filling current one
JoseConseco opened this issue · 4 comments
I cant jump to next tabstop, unless I will fill the current one. For example for this snippet:
snippet integer "IntProperty"
$1: bpy.props.IntProperty(name="test", description='', default=${2: 1}, min=0, max=100, subtype='PERCENTAGE')$0
If I want to leave default value at $2, I press < tab > but it wont jump forward to $0 (only using ultiSnip build-in map < c-j > work for jump) . If I enter anything at $2, then I can < tab > jump forward no problem. It feels almost like I can jump only from insert mode (and select mode jump wont work)
My mappings:
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
['<S-Tab>'] = cmp.mapping(function(fallback)
if vim.fn["UltiSnips#CanJumpBackwards"]() == 1 then
vim.fn.feedkeys(t("<C-R>=UltiSnips#JumpBackwards()<CR>"))
elseif vim.fn.pumvisible() == 1 then
vim.fn.feedkeys(t("<C-p>"), "n")
elseif check_back_space() then
vim.fn.feedkeys(t("<S-tab>"), "n")
else
vim.fn.feedkeys(t("<S-tab>"), "n")
end
end, { "i", "s"}),
['<Tab>'] = cmp.mapping(function(fallback)
-- print('can jump ='..vim.inspect(vim.fn["UltiSnips#CanJumpForwards"]()))
if vim.fn["UltiSnips#CanJumpForwards"]() == 1 then
vim.fn.feedkeys(t("<C-R>=UltiSnips#JumpForwards()<CR>"))
elseif vim.fn.pumvisible() == 1 then
vim.fn.feedkeys(t("<C-n>"), "n")
elseif check_back_space() then
vim.fn.feedkeys(t("<tab>"), "n")
else
vim.fn.feedkeys(t("<tab>"), "n")
end
end, { "i", "s"}),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm({ -- remapped at bottom by autopairs
behavior = cmp.ConfirmBehavior.Replace,
select = false,
}),
-- ['<C-Space>'] = cmp.mapping.complete(),
['<C-Space>'] = cmp.mapping(function(fallback)
-- print(vim.inspect(vim.fn.complete_info()))
if vim.fn.pumvisible() == 1 then
if vim.fn.complete_info()["selected"] ~= -1 then
if vim.fn["UltiSnips#CanExpandSnippet"]() == 1 then
return vim.fn.feedkeys(t("<C-R>=UltiSnips#ExpandSnippet()<CR>"))
else
vim.fn.feedkeys(t("<cr>"), "n")
end
else
vim.fn.feedkeys(t("<C-e>"), "n")
end
elseif check_back_space() then
vim.fn.feedkeys(t("<cr>"), "n")
else
fallback()
end
end, { "i", "s", }),
},
I tried to create separate mapping
snoremap <tab> "<C-R>=UltiSnips#JumpForwards()<CR>"
but then using tab on $2 will create double-quote character for no reason (not sure why). I also tried remapping g:UltiSnipsJumpForwardTrigger to tab in ultisnips config, but then in conflicts with tab in cmp. Any ideas what is going on? WHy:
if vim.fn["UltiSnips#CanJumpForwards"]() == 1 then vim.fn.feedkeys(t("<C-R>=UltiSnips#JumpForwards()<CR>"))
wont jump to next tab if I wont fill in $2 ?
Thanks for reporting,
I tried to create separate mapping
snoremap <tab> "<C-R>=UltiSnips#JumpForwards()<CR>"
but then using tab on $2 will create double-quote character for no reason (not sure why)
it should be, then it works
snoremap <Tab> <ESC>:call UltiSnips#JumpForwards()<CR>
I'm investigating why it doesn't work by the current mapping ...
Seems as of now, 's' map does not work as it mentioned from nvim-cmp
['<Tab>'] = cmp.mapping(function(fallback)
...
end, { "i", "s"}),
you can check like:
:verbose imap <tab>
it has the mapping, but
:verbose smap <tab>
it doesn't have any mapping. (actually, it had the mapping on the first time but I have no idea why the mapping was cleaned up)
For now, you can use as a workaround
snoremap <Tab> <ESC>:call UltiSnips#JumpForwards()<CR>
I will raise this issue with nvim-cmp author
Ok I found the the issue thanks to you and nvim-cmp author (no need to contact him, as this was UltiSnip problem). I will paste the fix here for other people:
we have to use :
vim.fn.feedkeys(t("<esc>:call UltiSnips#JumpForwards()<CR>"))
For tab jumping to work in both insert and select mode (even though UltiSnip is using two separate mappings - not sure why, but single line above works in nivm-cmp for both modes)
Tab still wont work, but in file linked above I found variable UltiSnipsRemoveSelectModeMappings
and bingo - UltiSnip was auto-removing tab mappings. We can disable this in Packer config:
use {'SirVer/ultisnips', requires='honza/vim-snippets',
config=function() vim.g.UltiSnipsRemoveSelectModeMappings = 0 end,}
Now tab mapping is not removed by UltiSnips, and we can jump in both insert and select mode
Hey, thanks, that was a good finding. I will update README for this.