Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add syntax highlighting to sublime text 2

Given the string "text text #{interpolation}" Sublime Text 2 highlights the whole string with one color. I would like to highlight the interpolated text so it is easy to pick out. When I press ctrl-shift-alt-p in the interpolated section Sublime tells me the namespace: source.ruby string.quoted.double.ruby source.ruby.embedded.source

I am wondering where I would define a rule to highlight this(I think in the tmLanguage file), what format that rule would take, and how to go about assigning a color to it.

like image 758
Tyler Avatar asked Feb 21 '13 18:02

Tyler


People also ask

How do I enable syntax highlighting in sublime?

To enable Syntax Highlighting click on “View” in the top bar, then hover your mouse over “Syntax”, and select your programming language from the list. Alternatively, if you save a document with a supported file extension, Sublime Text 3 will automatically apply the Syntax Highlighting for that language.

Can you highlight in Sublime Text?

🖍 Text Marker (Highlighter)This Sublime Text plugin allows temporarily and persistently marking all occurrences of selected words in a color; multiple marked selections can be added simultaneously, each marking the selections with different colors.

Where does sublime save syntax?

To create a new syntax definition, follow these steps: Go to Tools | Packages | Package Development | New Syntax Definition. Save the new file in your Packages/User folder as a . YAML-tmLanguage file.

How do I check syntax in Sublime Text?

For proper syntax highlighting (to tell where the comments are), select JavaScript -> JSON from the option list in the lower right of the Sublime window.


2 Answers

If you dig into the included Dawn.tmTheme file (one of the only included themes that does this highlighting properly) you'll find these highlighting rules for String embedded-source, for some reason some of the themes leave this out completely:

<dict>
    <key>name</key>
    <string>String embedded-source</string>
    <key>scope</key>
    <string>string source</string>
    <key>settings</key>
    <dict>
        <key>background</key>
        <string>#6F8BBA26</string>
        <key>fontStyle</key>
        <string></string>
        <key>foreground</key>
        <string>#080808</string>
    </dict>
</dict>
like image 109
tsundoku Avatar answered Oct 25 '22 20:10

tsundoku


This is better as it actually highlights the code within the interpolation as normal code, rather than all the same colour.

<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>#F92672</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>
   </dict>
</dict>
like image 34
Paul Odeon Avatar answered Oct 25 '22 20:10

Paul Odeon