Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom syntax highlighting in Sublime Text 2

I want to use Sublime Text as log viewer. That's why I need to create tmlanguage file for highlighting of word "ERROR" (and some others). Is there any spec of tmlanguage xml, or can you give me basic example of syntax-highlighting file for sublime text 2?

I've not found the answer in a similar question: Syntax specific highlighting with Sublime Text 2

like image 787
sev3ryn Avatar asked Mar 05 '13 10:03

sev3ryn


People also ask

How do I get syntax highlighting in Sublime Text?

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.

How do I change the syntax in Sublime Text?

sublime-syntax file, then just download it and copy it to ~/. config/sublime-text-3/Packages/User . It will then be available in the syntax menu at the very bottom right of the Sublime window, either on its own (it will say "SystemVerilog") or under the User submenu, depending on your setup.

How do I change the syntax color in Sublime Text?

Go to the folder where sublime_text3 binary is. Go to Packages folder Open Color Scheme - Default. sublime-package Find the concern color scheme. Open it in some editor and change the values as per requirement.

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.


2 Answers

Sublime Text uses the same syntax highlighting as TextMate. The grammar can be found here. I'd recommend working in JSON then converting to XML, since it's easier (at least it is for me) to read. The PackageDev plugin will give you a starting snippet for defining a new syntax. It also contains some syntax highlighting for configurations, as well as a Plist to JSON converter. Below is a snippet from a protobuf syntax definition file that highlights specific words. As for the colors of the highlights, you will have to look through your color scheme file. In the below example, you would look for the scope "constant.language" for the color it uses. You probably don't need to edit the color scheme, unless you want something other than what is already built into your scheme.

{ 
    "name": "Protocol Buffers",
    "scopeName": "source.proto",
    "fileTypes": ["proto"],
    "patterns": [{
            "match": "\\b(bool|bytes|double|fixed32|fixed64|float|int32|int64|sfixed32|sfixed64|sint32|sint64|string|uint32|uint64)\\b",
            "name": "constant.language.proto"
    }],
    "uuid": "8c8714d5-43ef-43d2-abd9-c9088901ddd5"
}
like image 146
skuroda Avatar answered Oct 16 '22 06:10

skuroda


You can play around with this app. A lot of the languages have nice definitions in them you can work from.

http://tmtheme-editor.herokuapp.com/#/Cobalt

like image 31
geedew Avatar answered Oct 16 '22 05:10

geedew