user3816764
user3816764

Reputation: 489

How to modify snippets in Sublime 3?

I want to change up my for loop snippets in Sublimetext 3.

One example is the forv for vector loop. I'd like to have that use an auto iterator instead of a vector iterator, as I often use std::array.

But I can't find these snippets anywhere, or where to edit them.

Upvotes: 2

Views: 1307

Answers (1)

Atilla Ozgur
Atilla Ozgur

Reputation: 14701

Best practice is overriding snippets. Create a snippet with the same name as you want to override and save it to User packages directory. Details are given here. Most easy way to find User packages directory is Browse Packages Menu Option. It will show you the directory where user packages saved.

I looked at where sublime installed and found C++.package file (MacOS /Applications/Sublime Text.app/Contents/MacOS/Packages\C++.sublime-package) . I unarchived it and found snippets.

Your snippet is following

<snippet>
    <description>Vector For Loop</description>
    <content><![CDATA[for (std::vector<$1>::iterator ${3:i} = $2.begin(); $3 != $2.end(); ++$3)
{
    $0
}]]></content>
    <tabTrigger>forv</tabTrigger>
    <scope>source.c, source.objc, source.c++, source.objc++</scope>
</snippet>

Create New snippet and copy paste this code. Change it according to your tastes. Save it to default snippet directory.

Upvotes: 2

Related Questions