Sublime Forum

Sublime Text: how to correct SQL Server syntax

#1

I am new to Sublime Text (version 3) and I am experiencing difficulties to get a proper SQL syntax highlighting.

Whenever I am looking at SQL queries, ST considers “#” as comment. For example, here everything beyond # gets greyed out:

INSERT INTO #TEST (A,B,C,D)
VALUES ('a','b','c','d')

I would like to correct this, so I looked around for answers for weeks but none of them works…

I started by looking in C:\Program Files\Sublime Text 3\Packages to find the file SQL.sublime-package.

I found this text in the comments section:

- match: "#"
  scope: punctuation.definition.comment.sql
  push:
   - meta_scope: comment.line.number-sign.sql
    - match: \n
      pop: true

So I tried to edit it:

  • Deleting the text block results in a Sublime Text error:

Error loading syntax file “Packages/SQL/SQL.sublime-syntax”: Unable to read Packages/SQL/SQL.sublime-syntax

  • Changing the # sign by something else (e.g. “–”): no effect

Do you have a solution to get a proper SQL syntax highlighting in Sublime Text 3?

Thanks a lot

0 Likes

#2

Not sure, whether it is what you need, but there are some SQL syntax packages at packagecontrol.io.

PostgreSQL: https://packagecontrol.io/packages/PostgreSQL%20Syntax%20Highlighting package
Oracle: https://packagecontrol.io/packages/Oracle%20PL%20SQL

Otherwise you’d need to create an overriding syntax for the builtin one.

Easiest way maybe the PackageResourceViewer package to do that. It can extract the builtin SQL syntax to the proper place at %APPDATA%\Sublime Text 3\Packages\SQL\SQL.sublime-syntax. This file than overrides the builtin syntax definition.

Removing the the whole textblock (line 143 to 148) from that file should work then.

    - match: "#"
      scope: punctuation.definition.comment.sql
      push:
        - meta_scope: comment.line.number-sign.sql
        - match: \n
          pop: true
0 Likes

#3

This question was also asked recently on StackOverflow; my answer there also provides step by step instructions if you’re new to these sorts of modifications.

1 Like