Sometimes I use Sublime Text for writing reminders. I always use the same layout for this task which looks like this :
>Title
>>Subtitle
>>>Comment
> Title
>> ...
Where a >
represent a tab character
So I'm wondering if it's possible to create my own syntax highlighting for this kinds of files, with one color for the title, another one for the subtitle and the regular color for the comment.
Syntax highlighting is performed using
.tmLanguage
syntax definitions. They are formatted in Apple's XML-based PLIST format, although thanks to the excellent Sublime pluginPackageDev
they can be written in JSON or in YAML, which I chose for its compactness, and the fact that I get sweet syntax highlighting with it using my theme*.So, your syntax is very straightforward. You'll have three rules:
Everything else will be displayed by Sublime as plain text.
Here it is, in YAML:
Everything is pretty straightforward. The name is what shows up in the bottom right corner of Sublime, it was written by me, its base scope name is
text.reminders
, opening a file with the.todo
extension will automatically apply this syntax, and the UUID is just a unique identifier. As I mentioned above, there are three patterns. One thing to keep in mind: this will only match if the line begins with a literal tab character, not space characters being inserted as a tab! That means you'll need to selectView -> Indentation
and make sureIndent Using Spaces
is NOT checked. Just for good measure, selectView -> Indentation -> Convert Indentation to Tabs
as well. These settings can be applied just to "Reminders" views, I'll cover that later.So we have our YAML, which is useless if you don't have
PackageDev
. However, translated to a PLIST it works much better:In Sublime, create a new file with XML syntax and copy the above XML into it. Find your
Packages
directory by selectingPreferences -> Browse Packages...
then save this new file asPackages/User/Reminders.tmLanguage
(make sure theL
intmLanguage
is capitalized). There should now be a "Users -> Reminders" option in the language list in the bottom right of Sublime, or through theView -> Syntax
menu option.However, there's one more thing to do - get coloring. To do this you'll need to modify your
.tmTheme
color scheme file. Since you're using Sublime Text 2 (I assume), it's pretty easy. OpenPreferences -> Settings-User
and check the value of"color_scheme"
. Open the color scheme file by selectingFile -> Open...
, navigating to thePackages
directory you found earlier withPreferences -> Browse Packages...
, and opening the file in whatever subdirectory it's in. For example, if your settings file says"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme"
you'll navigate to thePackages/Color Scheme - Default
directory in the open file dialog and openMonokai.tmTheme
. Super easy.Now that you have your color scheme file open, you can set the syntax to XML if you want, then scroll all the way down to the bottom. You'll want to insert your new colors (I'll get to that in a minute) above the lines that say:
The UUID may not even be there, it might just say:
Regardless, whichever is there should always be the last lines in the file, or things will break. At any rate, above these lines, insert the following dicts:
Feel free to customize the
foreground
andbackground
colors and thefontStyle
attributes ("bold" and "italic" are the only working values) however you like.One more thing, if you'll remember - setting Sublime to use tabs just in Reminders views. Create a new file using JSON syntax, or if you installed
PackageDev
, with "Sublime Settings" syntax. Add to it the following:(Yes, I know "todo" is already in the language definition, I just like to be safe). You can add any other option here that's used in the
Preferences -> Settings-Default
and... -> Settings-User
files, just make sure the file is valid JSON. Save the file asPackages/User/Reminders.sublime-settings
.And that's it! You may need to restart Sublime for the changes to kick in, but then you're all set. To recap, the steps to making a new syntax definition are as follows:
PackageDev
, your life will be a lot easier..sublime-settings
file for syntax-specific settings like tabs.* linked in my user profile if you're interested...