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:
Error loading syntax file "Packages/SQL/SQL.sublime-syntax": Unable to read Packages/SQL/SQL.sublime-syntax
Do you have a solution to get a proper SQL syntax highlighting in Sublime Text 3?
Thanks a lot
You're on the right track; what you tried should work for you. If you get an error indicating that Sublime can't load the syntax, the most likely cause is that you deleted too much or altered the file in some other subtle way. sublime-syntax
files are YAML, and as such they're sensitive to things like indentation.
Note also that doing anything in the Packages folder directly is a Bad Idea; modifying a sublime-package
file works in the short term, but they're upgraded by removing them and replacing them. So unless you're the one that made the file in the first place, modifying the contents directly is a recipe for your change to be unceremoniously removed at some future point when you least expect it.
Making the following changes worked for me. This uses the OverrideAudit package to make the change (disclaimer: I am the package author). That will let you easily make the change in a safe way and also let you know if the underlying package ever gets upgraded.
OverrideAudit: Create Override
SQL
package, then the SQL.sublime-syntax
filecomments:
to see the context that contains all of the match patterns that represent comments. This should be around line 128, depending on what version of Sublime you're using comments:
- match: "--"
scope: punctuation.definition.comment.sql
push:
- meta_scope: comment.line.double-dash.sql
- match: \n
pop: true
- match: "#"
scope: punctuation.definition.comment.sql
push:
- meta_scope: comment.line.number-sign.sql
- match: \n
pop: true
- match: /\*
scope: punctuation.definition.comment.sql
push:
- meta_scope: comment.block.c
- match: \*/
pop: true
comments:
- match: "--"
scope: punctuation.definition.comment.sql
push:
- meta_scope: comment.line.double-dash.sql
- match: \n
pop: true
- match: /\*
scope: punctuation.definition.comment.sql
push:
- meta_scope: comment.block.c
- match: \*/
pop: true
As soon as you save the file, the change should take effect immediately. If you check the Sublime console with View > Show Console
you should see a line that says generating syntax summary
, which indicates that Sublime has seen and reloaded the syntax. If there's an error during this process, it will be displayed here.
After performing these steps, your sample text renders like this (using the Adaptive
theme and the Monokai
color scheme:
If you've previously modified the actual sublime-package
file this may not work. In such a case you may need to do a reinstall of Sublime to get the original file back; doing so won't remove your settings. Alternatively you can download the Windows portable version from the Sublime website (even if you're not using windows) and get the pristine package from there to replace the one you modified.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With