FrostKiwi
FrostKiwi

Reputation: 821

Sublime Text C89 autocompletion

I'm using ST3 and code in the C89 standard. The super useful for-loop auto completion completes to:

for (int i = 0; i < count; ++i)
{
    /* code */
}

But this does not honor the standard. Can this behavior be changed in some config file to complete to:

int i = 0;
for (i < count; ++i)
{
    /* code */
}

?

Upvotes: 1

Views: 168

Answers (2)

Nipun Thennakoon
Nipun Thennakoon

Reputation: 3734

This is actually a snippet which is provided by c++ package that ships with sublime (that package covers both C and C++ due to their similarities).

The snippet which is responsible for the auto complete is 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>

You can modify that as you prefer. To do this,

  1. Install PackageResourceViewer for sublime. It lets you to look inside sublime packages.
  2. Open the Command pallete using ctrl+shift+p.
  3. Enter prv:o and select PackageResourceViewer: Open Resource from the list.
  4. Type C++ and navigate to Snippets\030-for-int-loop-(fori).sublime-snippet
  5. Modify the code to with this.

    <snippet>
         <description>For Loop</description>
         <content>
         <![CDATA[int ${2:i} = 0;
    for ( ${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>
    
  6. And save the file.

Upvotes: 1

Ina Tsetsova
Ina Tsetsova

Reputation: 365

You can find how to add specific auto- completion in the Sublime Text docs here - http://docs.sublimetext.info/en/latest/extensibility/completions.html. If you already have a Sublime Text package which is performing the C autocomplete for you, you might have to disable it.

Upvotes: 0

Related Questions