Writing custom completions in Sublime Text 2
Asked Answered
H

2

12

Sublime Text 2 comes with many built-in completions/templates for common idioms. In C++, these include for loops with fields, etc - if I wrote vec and pressed tab, it would expand to std::vector<field> v; where field is a writeable field. Many of these are written in a style that I do not like or do not provide things that I would like them to, and some that I want to use do not exist. Is there a way to modify these built-in "completions" and write my own?

Holography answered 18/6, 2012 at 14:53 Comment(1)
these are snippets, you can write your own ones and edit the C++ ones very easily, they live in your packages/c++ folderMease
J
8

I believe you're looking to customize the snippets.

Go to Preferences --> Browse Packages --> C++ and make whatever changes you need :)

Joannejoannes answered 18/6, 2012 at 14:58 Comment(1)
Thanks! I didn't know the terminology.Holography
C
12

You can edit the default ones by editing the files that generate them inside of your Packages directory. Just browse through the folders to the specific language or check the Default folder to find the right file to edit for one of the defaults.

You can create custom snippets as well as modify the default ones by going to Preferences > Browse Packages > User and creating a new file with the .sublime-snippet extension.

Then inside the file paste the following:

<snippet>
    <content><![CDATA[Type your snippet here]]></content>
    <!-- Optional: Tab trigger to activate the snippet -->
    <tabTrigger>xyzzy</tabTrigger>
    <!-- Optional: Scope the tab trigger will be active in -->
    <scope>source.python</scope>
    <!-- Optional: Description to show in the menu -->
    <description>My Fancy Snippet</description>
</snippet>

More info here.

Alternatively, you can go to Tools > New Snippet and it will open the snippet template in a new file that you can then save and name with the same extension as above.

Another option, is this way using the Gist package. The only thing I don't like about this setup is it creates a new file with the snippet rather than pasting it into your current file at your cursor. Still it is good for coordinating your most used snippets across several computers.

Cristicristian answered 19/6, 2012 at 2:1 Comment(0)
J
8

I believe you're looking to customize the snippets.

Go to Preferences --> Browse Packages --> C++ and make whatever changes you need :)

Joannejoannes answered 18/6, 2012 at 14:58 Comment(1)
Thanks! I didn't know the terminology.Holography

© 2022 - 2024 — McMap. All rights reserved.