Sublime Forum

Java for auto complete

#1

Hello, I recently started to program in java with sublime text,
I want to when i write “for” and press TAB, it automatically write this :
for (int i = 0; i<4; i++) {

}

I can already do it with a new Snippet, but what i want is : When i write an another “for” in the first “for”
it paste the same thing but change the variable “i” to an another one ( “j” then “k”, “l”, “m” …)
Is there a way to do this ?

0 Likes

#2

You could achive it with the following semi-automatic snippet:

<snippet>
	<content><![CDATA[for (int ${1:i} = 0; ${1:i} < ${2:10}; ${1:i}++) {
	$0
}]]></content>
	<tabTrigger>for</tabTrigger>
	<scope>source.java</scope>
	<description>for</description>
</snippet>

You still need to enter the iteration index, but the snippet will place it to all positions in one step.

0 Likes