Sublime Forum

Highlight or bold 'this' keyword in JavaScript

#1

How do I make the ‘this’ keyword in JavaScript be a difference font color or bold or italics to make it stand out?

Thanks!

0 Likes

#2

If you search for ‘this’ in the ‘JavaScript.tmLanguage’ setting you should (hopefully) find something like:

<dict> <key>match</key> <string>\b(super|this)\b</string> <key>name</key> <string>variable.language.js</string> </dict>
… but I modified this file so I’m not sure whether this was there already or not (?).

Anyway, assuming it’s there, open your chosen ‘tmTheme’ file. Look through it and you’ll see that it follows a regular pattern. Add the following, perhaps towards the top of the file.

<dict> <key>name</key> <string>Super this (JavaScript)</string> <key>scope</key> <string>source.js variable.language.js</string> <key>settings</key> <dict> <key>fontStyle</key> <string>italic</string> <key>foreground</key> <string>#33A1DE</string> </dict> </dict>
The ‘source.js’ part of the scope name is probably not necessary, but it’ll do no harm.

If you don’t want italics just delete this word (but leave the empty string tag). You can insert a ‘background’ key if you like.

0 Likes

#3

That worked! I did have the code in my JavaScript.tmLanguage file. I was able to copy the theme that I was using to my User directory and then add the second code snippet.

Thank you so much. I really appreciate the help!

0 Likes