That is actually a snippet, which is provided by the C++ package that ships with Sublime (that package covers both C and C++ due to their similarities).
The snippet in question is stored in Packages\C++\Snippets\030-for-int-loop-(fori).sublime-snippet
, and looks like this:
<snippet>
<description>For Loop</description>
<content><![CDATA[for (int ${2:i} = 0; $2 < ${1:count}; ${3:++$2})
{
${0:/* code */}
}]]></content>
<tabTrigger>for</tabTrigger>
<scope>source.c, source.objc, source.c++, source.objc++</scope>
</snippet>
See the link above for more information on the format of the snippet file itself. Something to note is that the XML CDATA
portion of the snippet is important; if you remove it, the snippet won’t work.
This file is actually stored inside of a sublime-package
file that ships with Sublime, so it’s not a good idea to modify it directly, as the change will be lost on Sublime update/reinstall.
You could duplicate the above snippet by selecting Tools > Developer > New Snippet...
from the menu and replacing the contents of the generated snippet stub with the code above, shifting the location of the opening brace as appropriate.
An issue with this is that the existing snippet in the C++ package will still remain, which means that there will be two identical looking completions offered, only one of which being the one that you want.
You can stop this from happening by creating an override for the original file, which will mask its contents with what you provide without directly modifying the package. Such an override remains in your Packages
directory between reinstalls and updates so it’s contents aren’t lost like they would be if you modified the package file directly.
The easiest way to create an override for this would be:
-
Install PackageResourceViewer if you haven’t already (it’s an invaluable tool for looking inside of and tweaking packages)
-
Open the command palette via Tools > Command Palette
or the associated key for your platform (visible in the menu if you don’t know it offhand)
-
Enter the text prv:o
and select the PackageResourceViewer: Open Resource
command from the list
-
Select the C++
package, then Snippets
, then 030-for-int-loop-(fori).sublime-snippet
(you can use fuzzy searching here to navigate the list faster)
-
Either erase the entire contents of the file OR modify it as appropriate for your uses (see below)
-
Save the file; PackageResourceViewer will save it as an override file automatically in the correct location.
In step #5 above, you have a choice; you can edit the snippet directly to format the code the way you want it, or you can erase the entire contents and save it as an empty file. In the first case that’s the only step you need to do to make the snippet work like you want. In the second case that will remove the existing snippet, in which case you also need to provide your own as outlined above.
Note that an override remains forever, so your override will remain in place even if the official version of the file changes in a future Sublime release. I’m having a hard time envisioning improvements in the world of for loops, though, so that’s probably nothing to be concerned about.