Sublime Forum

How can I skip variable in sublime text 2 snippet?

#1

I have sublime text 2 snippet like this:

on('${1:click}', ${2:'$3', }function (e) { $0 return false; });

So if I trigger the snippet first is highlighted click, next is highlighted **’’, ** and here I have an option to either enter a value with next tab or just delete the the selected text if I don’t want to use this highlighted block at all.

The problem is if I hit Delete to delete the highlighted text I want to jump to the next var which in my case is $0. But instead I get a blank tab hit which is for the $3 var which is already deleted from var $2.

This is the way E-texteditor work if you delete some var which contains another var iniside you jump directly to the next after the deleted var not inside of it.

Is this possible to achieve with Sublime Text 2?

Thanks!

0 Likes

#2

Here is an even more useful snippet I’ve used million times in E-texteditor:

<div${1: id="${2}"}${3: class="${4}"}>
	$0
</div>

which resembles to this:

<div id="" class="">
	
</div>

Basically what this means is that I always have my divs with either a class or an id.

In E-texteditor:
The key sequence for div with id is: div, Tab, Tab, write the id, Tab, Del, Tab - continue with the div’s content.
The key sequence for div with class is: div, Tab, Del, Tab, Tab, write the class, Tab - continue with the div’s content.

In Sublime Text 2:
The key sequence for div with id is: div, Tab, Tab, write the id, Tab, Del, Tab, Tab - continue with the div’s content.
The key sequence for div with class is: div, Tab, Del, Tab, Tab, Tab, write the class, Tab - continue with the div’s content.

Now if I have to execute this snippet +200 times a day, it hurts not only my performance but my nerves too.

In other words I really like Sublime Text 2 and I use it a lot but I never use it when I’m slicing (working). And this is one of the major bugs preventing me from switching to Sublime and actually buy it. It’s a bug because it has no point to have a blank tab hit for something that is already deleted.

I hope someone will answer and give me a direction how can I fix this behaviour.

Here is the entire snippet:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
	<dict>
		<key>name</key>
		<string>m2k-div</string>
		<key>uuid</key>
		<string>A73D3916-DED9-4BDD-95EC-73C6383583D5</string>
		<key>tabTrigger</key>
		<string>div</string>
		<key>content</key>
		<string>&lt;div${1: id="${2}"}${3: class="${4}"}&gt;
	$0
&lt;/div&gt;</string>
		<key>scope</key>
		<string>text.html</string>
	</dict>
</plist>
0 Likes

#3

I know what you mean, it is quite frustrating sometimes. It is also annoying when I insert some text inside a snippet which also happens to be a ‘tabable/expandable’ snippet, but hitting tab sends the caret to the next tab stop in the initial snippet. The only way is to press escape to stop the initial snippet from being ‘in use’ anymore. Does anyone have any thoughts on how this could be improved?

0 Likes

#4

I reported this few months ago, was one of the first things i found it buggy. Jon know about this, but no fix yet. Still hoping.
Pressing esc is not a very reliable solution, because sometimes you just want to skip some of the triggers (like… let’s say deleted triggers?).

0 Likes