Sublime Forum

Creating snippets

#1

When creating snippets is there anyway I can make it detected whitespace

<snippet>
	<content><![CDATA[
public static void main(String[] args)
{
	$0
}
]]></content>
	<tabTrigger>main</tabTrigger>
	<scope>source.java</scope>
</snippet>

this will instead produce

public static void main(String[] args) {
	
}

(the brace is one line above where it should have been according to the snippet)
many thanks

0 Likes

#2

I am pretty sure that you are completing the wrong, default “main” snippet. What you describe should work under normal circumstances.

Where did you save this snippet file to?

0 Likes

#3

I have saved it to this path here
C:\Users\Mark\AppData\Roaming\Sublime Text 2\Packages\User

I have also now released i keep updating the snippet yet its not updating in sublime e.g i changed the whole snippet to “asdfsaf” and then tried again and it didn’t update and give “asdfsaf”.

edit: to be honest that happens since sublime is a bit slow to detect changes to the snippets for some reason.

but the original issue remains.

0 Likes

#5

Try with the tab trigger main2. (both in snippet and when testing)

1 Like

#6

yes you’re correct main2 works fine!

ok so what did you mean before about the default main?

was there already a snippet called main?

more importantly is there anyway it can work with main?

0 Likes

#7

Exactly. There already is a snippet for main which completes to what you wrote in the first post. You can either remove that snippet (since you are on ST2) or just modify it. Or you use ctrl+space to select your custom main snippet instead of tab-completing directly. The modification will likely be reverted on the next Sublime Text update though.

If you used ST3, you could have made use of override packages and PackageResourceViewer (package) to permanently override the snippet in-place.

1 Like

#8

ok thank you! solved all my problems!

0 Likes