Sublime Forum

Syntax colouring of variables

#1

Hi, I am using a theme which has coloured variables and user functions in python, but this does not show up in the editor.

Does the editor not get enough context to make this possible? Or am I doing something wrong?

Thanks.

0 Likes

#2

Make a note of the scope selector in the theme you’re using and try to locate it in the syntax def for your language. That way you will know whether your syntax def provides enough context for your theme.

Also, note that scope selectors don’t need to match exactly, so “variable.foo.bar” in a syntax def would match against a syntax def defining “variable” only.

Alternatively, switch between a couple of themes and see whether you get the highlighting you want.

0 Likes

#3

Thanks for the reply.

I’ve tried all the themes; none of them colour variables.

The python syntax definition doesn’t have plain variables. I see that it uses regexes - is it even possible to identify a variable like this?
You say “my syntax def”: do people use one other than the default?

I’m not sure whether I’m asking for something that’s completely impossible or whether everyone is using it.

0 Likes

#4

It isn’t always possible to match variables with regexes in syntax defs (which Sublime uses to create scopes, which in turn color schemes use to highlight stuff). That’s the case for python; you cannot reliably tell variables apart from other tokens.

However, it works for Powershell, for instance:

bitbucket.org/guillermooo/power … age#cl-266

You normally use “default” syntax defs, not customised ones, yeah, that was a manner of speaking.

More info on syntax defs:

sublimetext.info

0 Likes