How to add Ruby string interpolation highlighting for Sublime

To add Ruby string interpolation highlighting for Sublime Text 2, you need to edit your .tmTheme file. It can be found in your SublimeText 2, go to Preferences, then Browse Packages. This will open up your finder or Windows Explorer. Look for the folder “Color Scheme – Default”, you should be able to find themes like Monokai and others inside.

In order to add the syntax highlight for Ruby’s ${} in strings, for example:

[code language=”ruby”]puts "Working in #{pwd}"[/code]

Open up your .tmTheme file and add the following lines:

[code language=”xml”]
<dict>
<key>name</key>
<string>Embedded Ruby Punctuation</string>
<key>scope</key>
<string>string punctuation.section.embedded.ruby</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#75715E</string>
<key>background</key>
<string>#444444</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Embedded Ruby Source</string>
<key>scope</key>
<string>string source.ruby.embedded.source</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#FFFBF7</string>
<key>background</key>
<string>#444444</string>
</dict>
</dict>
[/code]

You can change the colors of background and foreground to your liking too. Hope you’ll find this useful!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>