Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How do I create a new snippet in TextMate 2? When I go to Edit Bundles I can't figure out how to create a new snippet.

share|improve this question

2 Answers 2

up vote 39 down vote accepted

TextMate 2 has not yet been released and is in an alpha state. The bundle editor is one of the areas that are very much not final.

While a proof-of-concept bundle editor is included, it is provisional, has some flaws, and not how we envision the final bundle editor to be.

These instructions are for Version 2.0 (8956), current as of January 20, 2012. Think before you down vote.


Select Bundles » Edit Bundles… in the TextMate 2 menu.

Select the bundle you want to add a snippet to, e.g. HTML. Press Cmd-N to create a new bundle item, and select Snippet.

It will be automatically added to the Menu Actions subsection. You can change its settings, such as keyboard shortcut, in the drawer, and its contents in the editor at the bottom.

Enter a tab trigger in you want a sequence of characters (e.g. snip), followed by pressing Tab to trigger the snippet, or assign a keyboard shortcut.

Scope Selector specifies in which scopes the snippet can be inserted using the trigger. To find out the scopes of your selected language, switch to a document with that syntax, and press Ctrl-Shift-P to show all applicable scopes below the cursor.

For example, if you want your snippet to be available anywhere in HTML documents, enter text.html.basic; or source.shell for shell scripts. You can enter multiple scopes, separated by comma, or only scope name prefixes (e.g. source) to apply to all matching source.* scopes.

For anything else, just look at all the other snippets you can access from that window and see how they achieve some desired behavior.

share|improve this answer

To add: after you add a snippet to a bundle, you might well want to alter where it appears in the bundle menu. This is currently unsupported in the GUI (as of 2.0-alpha.9401).

You can do it manually if you are a relative expert. You can break the bundle by making errors here, so don't venture in unthinkingly.

  1. Find the UUID of your new bundle item (or any bundle item you wish to move

    • the item will be in a sub folder of

    "~/Library/Application Support/Avian/Bundles/yourbundle/"

  2. option-click the bundle item to open as text in textmate, and copy the uuid string. This will look something like:

    <string>E1ABEC5E-DF5F-4C09-BA9F-E17504F456C0</string>
    
  3. Open the info.plist of your bundle

    • This is an xml-type file listing the items of the menu, including sub-menus and the items they contain. You want to add your uuid string to the appropriate location in the appropriate list. If you wanted it in an existing submenu called "Development" just search the plist for "Development", and above there, you will see the array of items: paste your new snippet in where you want it to go

    • The plist can be found at

    "~/Library/Application Support/Avian/Bundles/yourbundle/info.plist"

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["                  <li><a href=\"//area51.stackexchange.com\" title=\"proposing new sites in the Stack Exchange network\">Area 51</a></li>\r\n                        <li><a href=\"//careers.stackoverflow.com\">Stack Overflow Careers</a></li>\r\n                    \r\n                </ol>\r\n            </td>\r\n    </tr>\r\n</table>\r\n                </div>\r\n            </div>\r\n\r\n            <div id=\"copyright\">\r\n                site design / logo &#169; 2015 stack exchange inc; user contributions licensed under <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc by-sa 3.0</a> \r\n                with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2015.7.7.2698\r\n            </div>\r\n            \r\n        </div>\r\n    </div>\r\n    <noscript>\r\n        <div id=\"noscript-warning\">Super User works best with JavaScript enabled<img src=\"http://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif\" alt=\"\" class=\"dno\"></div>\r\n    </noscript"], "copyright__copyright__copyright": ["ng submenu called \"Development\" just search the plist for \"Development\", and above there, you will see the array of items: paste your new snippet in where you want it to go\n\n    \u2022 The plist can be found at\n\n    \"~/Library/Application Support/Avian/Bundles/yourbundle/info.plist\"\n\nshare|improve this answer\n\nYour Answer\n\n\u00a0\ndiscard\n\nBy posting your answer, you agree to the privacy policy and terms of service.\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question.", "ng submenu called \"Development\" just search the plist for \"Development\", and above there, you will see the array of items: paste your new snippet in where you want it to go\n\n    \u2022 The plist can be found at\n\n    \"~/Library/Application Support/Avian/Bundles/yourbundle/info.plist\"\n\nshare|improve this answer\n\nYour Answer\n\n\u00a0\ndiscard\n\nBy posting your answer, you agree to the privacy policy and terms of service.\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question.", "ng submenu called \"Development\" just search the plist for \"Development\", and above there, you will see the array of items: paste your new snippet in where you want it to go\n\n    \u2022 The plist can be found at\n\n    \"~/Library/Application Support/Avian/Bundles/yourbundle/info.plist\"\n\nshare|improve this answer\n\nYour Answer\n\n\u00a0\ndiscard\n\nBy posting your answer, you agree to the privacy policy and terms of service.\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}