Search code examples
sublimetext3sublime-text-plugin

How do I change the name of Syntax in Sublime Text?


I'm using a package for sublime named the "C++ Starting Kit", and it has an enhanced syntax specifically for C and C++. It seems that I can't set this as my default syntax for C or C++ as sublime keeps changing the default back to the default syntax. From testing a bit, it seems that this problem is caused by the names of the starter-kit's syntax being the same as the default syntax, so I am trying to find a way to change the starter-kit's syntax name to be something like "C++ST".


Solution

  • First you'll need to install PackageResourceViewer to access the files stored in the zipped .sublime-package file. Once installed, open the Command Palette and select PackageResourceViewer: Extract Package and select C++ Starting Kit from the dropdown. Next, select Preferences -> Browse Packages... to open Sublime's Packages directory in your operating system's file manager:

    • Linux: ~/.config/sublime-text-3/Packages
    • OS X: ~/Library/Application Support/Sublime Text 3/Packages
    • Windows Regular Install: C:\Users\UserName\AppData\Roaming\Sublime Text 3\Packages
    • Windows Portable Install: InstallationFolder\Sublime Text 3\Data\Packages

    Go to the C++ Starting Kit directory and open the C.tmLanguage and C++.tmLanguage files in Sublime with XML syntax. Near the top, look for the following:

    <key>name</key>
    <string>C</string>
    

    or

    <key>name</key>
    <string>C++</string>
    

    Change the <string> values to C ST and C++ ST, respectively, then save the files and close them. Next, in your file manager, rename C.tmLanguage to C ST.tmLanguage and C.sublime-settings to C ST.sublime-settings, and do the same for the C++ .tmLanguage and .sublime-settings files as well.

    The changes should take effect immediately, but if not you can restart Sublime.