Sublime Forum

Custom syntax highlighting for certain variables

#1

I use different libraries in my projects to make things easier for myself. I was wondering if it’s possible to give different colors to the variables associated with those libraries. I’m using sublime text 3 with Monokai theme.

0 Likes

#2

You can use YAML Macros to extend an existing syntax.

Something like:

%YAML 1.2
%TAG ! tag:yaml-macros:YAMLMacros.lib.extend:
---
!extend
_base: JavaScript.sublime-syntax
name: JavaScript (with library constants)

contexts: !merge
  literal-variable: !prepend
    - match: |-
        (?x)\b(?:
          someConstant
          |otherConstant
        )\b
      scope: support.constant.someLibrary.js
      pop: true
0 Likes