Syntax specific highlighting with Sublime Text 2

后端 未结 2 863
心在旅途
心在旅途 2021-01-13 07:54

I\'m wondering if there is a way to have two different tag colours (\"colors\" for those in the US) for different language tags in the same file.

For example, lets s

2条回答
  •  星月不相逢
    2021-01-13 08:18

    Yes, as long as the tags can be identified as having different scopes by your installed language definitions, you can edit your colour scheme to target those scopes with specific colours and other styles.

    In your packages folder, language scopes are defined in the .tmLanguage files for your installed languages, while styles are defined in the .tmTheme files in the "color scheme - default" folder.

    If you position your cursor inside a tag, and press shift+ctrl+alt+p (shift-cmd-p in OSX I think) the status bar will display the current scope. You can also copy this to the clipboard via the console with this command:

    sublime.set_clipboard(view.syntax_name(view.sel()[0].b))
    

    You can use this information to create your styles, a bit like css selectors, but with XML. For example I use this Coldfusion package and I have the scope selectors shown below in my custom .tmTheme file to distinguish cf tags from HTML tags.

    
        name
        Tag name
        scope
        entity.name.tag
        settings
        
            background
            #D8D0B6
            fontStyle
            bold
            foreground
            #647A4F
        
    
    
        name
        CF tag name
        scope
        entity.name.tag.conditional.cfml, entity.name.tag.declaration.cfml, entity.name.tag.other, entity.name.tag.cf, entity.name.tag.inline.other.cfml
        settings
        
            background
            #D8D0B6
            fontStyle
            bold
            foreground
            #990033
        
    
    

    More info on scope selectors.

提交回复
热议问题