Sublime Forum

Use tab to force "commit completion" inside snippets

#1

Let’s say I’m using LaTeX. I’m using the snippet which makes frac into \frac{$1}{$2}.

However, if I want to insert another \frac{}{} in the first pair or braces of the frac, it doesn’t work. Here’s what happens.

% Type `frac` to expand

frac|

% Press tab

\frac{|}{}

% Type another `frac` to expand

\frac{frac|}{}

% Press tab

\frac{frac}{|}

% Nooo! Not what I wanted. It should have expanded the second `frac`, instead of going to the next field:

\frac{\frac{|}{}}{}

Essentially I want to tell Sublime Text to prefer expanding a snippet over moving to the next snippet field if I’m already in a snippet. I’ve looked at the keybindings but I don’t really get how to do it.

I feel like this is a problem which would be extremely common, so I’m sure there’s a simple solution for it. Unfortunately my googling didn’t lead to much.

0 Likes

#2

Setting auto_complete_with_fields to true in preferences should do it.

0 Likes

#3

Thank you for the reply. Unfortunately I tried setting it to true but it didn’t work. Does it work for you?

0 Likes

#4

Yes it works, tried it right now.
auto_complete_commit_on_tab must be true too, but I guess you have it already.
It works if the autocomplete list is visible, so make sure it is.

0 Likes

#5

You can also press escape to cancel the remaining fields before you complete the inline snippet in case you only need this sometimes.

It would obviously be better if st supported nested snippets natively.

1 Like

#6

Ah, I see. I tried setting both of them to true, but it didn’t work. I don’t have the autocomplete window enabled though.

0 Likes

#7

Great, thanks! That works.

0 Likes