I'm using Sublime Text 2/3 to code in Typescript and Javascript.
But when the key of an object is also a valid keyword name, it gets highlighted like a keyword even though it is only a key in that case.
Example:
var test = { do: 'hello world' };
Is there a way to not highlight this kind of key as a keyword would?
The syntax highlighting is controlled by the tmLanguage file. In ST3 these are held in .cache files.
So follow these steps.
Tools -> Command Pallet
and Using Package Manager install PackageResourceViewerPackageResourceViewer: Open Resource
JavaScript
JavaScript.tmLanguage
Now you have the language definition file displayed for you.
For your case do a search for
do
until you find it sitting in the list of keywords namedkeyword.control.js
Having tagged the string
do
as a JavaScript Control Keyword that instruction will be respected in the .tmTheme file you have chosen for your colour scheme.If we use PackageResourceViewer in the same pattern as above to open the
Amy.tmTheme.cache
file and the search forcontrol
I find this instruction:That says that if I chose to use the
Amy
theme then when a .tmLanguage file identifies a string as akeyword.control
(a Control Keyword) the theme should apply the provided syntax highlighting.So what does all that tell us? If you want the string
do
to not always be treated as a Control Keyword you need to build a new set of regular expression (regex) tests than the ones currently in JavaScript.tmLanguage. If you can come up with a new regex that applies the rules you would like to have applied then you can add it to the .tmLanguage file and get the syntax highlighting you want.I would strongly suggest that you start by saving the
JavaScript.tmLanguage
file into yourUser
folder so you are working on a copy and your changes will not be discarded the next time ST3 upgrades.Now work on editing the .tmLanguage file until you get the behaviour you want. It seems to me your new regex should look for a trailing
:
immediately after the keyword and not tag such a string askeyword.control.js
. Knock yourself out playing with the ideas. If you have saved a copy into yourUser
folder and it all goes to custard the worst that can happen is you delete your .tmLanguage file and restart ST and you will revert to the default .tmLanguage file in thePackage
folder. The worst that can happen is you waste a couple of hours. But if you 'crack' the right regex pattern you have your own .tmLanguage file holding your preferred language definition that will be respected in every colour scheme and joy and happiness will abound in your world with an annoyance removed from your daily coding experience. Always a 'good thing (TM)'.Hope this all makes sense. Yell out if it doesn't and I'll try and do better.