SirVer / ultisnips

UltiSnips - The ultimate snippet solution for Vim. Send pull requests to SirVer/ultisnips!
GNU General Public License v3.0
7.52k stars 690 forks source link

I can't make UltiSnips to set <tab> as jump forward trigger #1554

Closed BODH1SATVA closed 4 months ago

BODH1SATVA commented 4 months ago

I want to set <tab> for both to expand and jump forward but it seems like vim.g.UltiSnipsExpandOrJumpTrigger = '<tab>' does not work. I thought that other maps could get in the way or it might be due to the conflict with other plugins, but I don't use <tab> in any other maps and I have tried deleting other plugins (left only VimTex and UltiSnips), It still would not work. Later I found that this does not work for any keys not just for <tab>. vim.g.UltiSnipsJumpBackwardTrigger = '<s-tab>' works fine though.

I use lazy.nvim as my plugin manager. I have tried updating UltiSnips but it says it's up to date.

I have tried more direct way and I changed my ultisnips.lua file inside my plugins folder to have

return {"SirVer/ultisnips", 

lazy = false, 
config = function()
vim.api.nvim_set_keymap('i', '<tab>', '<C-R>=UltiSnips#ExpandSnippetOrJump()<CR>', {noremap = true, silent = true})
end

}

This works with other keys ( <c-k> for example ) but not with <tab> (also this does not remove default mappings obviously). When I try to set <tab> this way and use command :imap<tab> it gives me <C-R>=UltiSnips#ExpandSnippet()<CR> instead of <C-R>=UltiSnips#ExpandSnippetOrJump()<CR> .


AshyAspen commented 4 months ago

I'm not sure about the specifics of your case, but I just thought I'd share that I was having a similar problem recently because I was trying to define the remap in a config file set in a snips.lua file in the "after" folder specifically for UltiSnips, like I do for most config stuff. I found that the was working for expanding but not jumping and wasn't sure why.

I ended up putting

vim.cmd([[                    
let g:UltiSnipsExpandTrigger = '<tab>'                              
let g:UltiSnipsJumpForwardTrigger = '<tab>'                                          
let g:UltiSnipsJumpBackwardTrigger = '<s-tab>'                                                 
]])

in my init.lua and everything works fine now like I was trying to get it.

Perhaps doing separate commands for forward and expand would work? Or moving it to a piece of your config that initializes sooner, if you're having a problem I was having? I'm not exactly sure but I thought I'd share. Sorry I can't help more.

BODH1SATVA commented 4 months ago

@AshyAspen I tried moving commands to init.lua file and tried separate commands. It still would not work. Thanks for suggestion though.

I also noticed that vim.g.UltiSnipsExpandTrigger does not work in my case. I can't set anything other then <tab> as an expand trigger.

I still don't have any idea what could be wrong here. I checked my config several times, all I have there is simple stuff like setting colorscheme, line numbers... and few other maps that don't use <tab> (most of them are for normal mode anyway).

BODH1SATVA commented 4 months ago

I have figured these out. I changed my ultisnips.lua file to have

return {"SirVer/ultisnips", 
lazy = false, 
init = function()
vim.g.UltiSnipsExpandOrJumpTrigger = '<tab>'
vim.g.UltiSnipsJumpBackwardTrigger = '<s-tab>'
end
}

Everithing works as it should now.

SirVer commented 4 months ago

Glad you made it work. I do not use Neovim and it is officially not supported by UltiSnips, hence i could not have helped in either case.