Is there a way for Sublime Text 2 to display different colors for Ruby "variables" vs "keywords"? The image below is an example of Ruby code with the default Monokai color scheme. I was hoping I could having the variables (list, x) be a different color than the keywords (each, print).
Currently, they're all tied to <key>foreground</key>
. I did try changing the variable
color, but that only changed for the |x|
.
No, there is not a way to do this with the default Ruby syntax that ships with Sublime. list
, each
, print
, and x
are all scoped as source.ruby
, meaning they don't have a specific scope that can be targeted by a color scheme. On the other hand, end
is scoped keyword.control.ruby
, and do
is keyword.control.start-block.ruby
(in addition to the base source.ruby
scope that applies to all elements), so if you have a rule in your color scheme for keyword
or keyword.control
, they can be colored differently. |x|
is punctuation.separator.variable.ruby
for the pipes |
, and variable.other.block.ruby
for x
, so those can be adjusted per your preferences.
Essentially, an item can only be colored if it has a distinct scope, and your color scheme contains a rule for that scope (or a more generalized version of it, but not a more specific version of it). Ruby is especially challenging as compared to Python, for example, as while Python methods always have parentheses at the end ( string_var.replace()
, for example) and regexes can be written to highlight anything between the dot .
and the parens as a function call, Ruby does not follow this paradigm, so the syntax highlighting definition (found in the various .tmLanguage
files) cannot distinguish between a method call and a simple attribute, and so cannot highlight them differentially. This is why list.each
in your program is only source.ruby
, and each
is not highlighted as a function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.