Tallboy
Tallboy

Reputation: 13417

How to make Ultisnips (vim) only trigger after a `>` character?

I want to make a snippet which only triggers after a > symbol, that way if I'm inside a (x<cursor>), and I hit tab it won't trigger, but if it's after an html tag like <div>x<cursor> it will trigger.

Upvotes: 0

Views: 360

Answers (1)

builder-7000
builder-7000

Reputation: 7627

You could use an insert-mode map:

inoremap > ><c-o>:echoe "inside tag"<cr>
inoremap < <<c-o>:echoe "outside tag"<cr>

replace echoe with the function or command you want to trigger inside html tags.

Edit:

inoremap > ><c-o>:silent! iunmap <c-v><tab<c-v>><cr>              
inoremap < <<c-o>:silent! imap <c-v><tab<c-v>> <Plug>SuperTabForward<cr>

If you have SuperTab plugin this should work. The first command disables tag completion when typing >. The second command renables tab completion when typing <.

Upvotes: 1

Related Questions