I'm writing C code and have some nice highlighting scheme but there is one thing I'd like to highlight and I can't figure out how. It's maths symbols like *;+;-;/;= ... and brackets {} [] (). I want them in the same color. I searched everywhere and the only thing I found was how to highlight specific keywords (I already used it for "FILE" keyword, I don't know why they didn't highlight it by default)
-
you don't (necessarily) need an IDE. http://stackoverflow.com/questions/1199267/braces-and-operators-coloring-in-vim-for-c – Karoly Horvath Jun 28 '14 at 08:19
-
Agreed. An excellent editor with good syntax highlighting is worth its weight in gold for tired eyes. You have several choices. KDE kdate/kwrite are both excellent with wide support for many programming and scripting languages. Gnome's gedit provides similar capability. On windows, Notepad++ is hard to beat. Try one, or all, and you will find syntax highlighting just a necessary to an editor as paper was for the pen... – David C. Rankin Jun 28 '14 at 09:13
-
Can use use regular expressions? If so something like `/[-=\*\+\/\{\}\[\]\(\)]+/` might work. – Salix alba Jun 28 '14 at 11:28
-
@szx I do no want any IDE I like gedit this is the only problem I have with it – Dominik Jun 30 '14 at 13:00
-
@KarolyHorvath You probably commented after someone (maybe moderator) edited the question the original topic was "gedit:..." so your vim solution is useless here :/ but thanks for trying – Dominik Jun 30 '14 at 13:00
-
@Salixalba I tried this before writing here, didn't work :( – Dominik Jun 30 '14 at 13:01
1 Answers
Looking at https://wiki.gnome.org/Apps/Gedit/NewLanguage which seem to be the gedit doc for how to set up cunstom sets of syntax highlights. This points to https://developer.gnome.org/gtksourceview/stable/lang-tutorial.html which says "Those regular expressions are PCRE regular expressions in the form /regex/options" following the documentation you can match individual characters like
<context id="escape" style-ref="escaped-character">
<match>\\.</match>
</context>
which matches \.
. The doc also has examples of complete regular expressions
<match>http:\/\/[^\s]*</match>
for matching a URL.
Putting this together you might want something like
<context id="maths" style-ref="my-math-characters">
<match>(\+|\-|\*|\/)</match>
</context>
(...)
is grouping, |
is alternation, \+
etc quotes a meta-character. I don't use gedit myself so this is untested. It probably best to start with a simple set of symbols to see if things work at all and then expand for your complete set of characters. Watch out for <
>
&
which have special meaning in xml so you may need to use <
etc.

- 7,536
- 2
- 32
- 38