Until you save a document in gedit, syntax highlighting is turned off. There are obviously good reasons for this -- people might get confused if certain words were randomly showing up in different colors. But for my purposes, I use gedit almost exclusively for HTML editing.
A lot of times I paste snippets of code into a new gedit document for quick editing, and I have to manually set the syntax coloring to HTML. Other times, I open ColdFusion (.cfm) documents, which gedit apparently doesn't recognize, and again I have to manually set the color to HTML. Both of these inconveniences would be fixed if I could find a way to tell gedit to automatically use HTML syntax highlighting for new documents and documents without a recognized file extension. Is this possible?
You can at least add file extensions in the html syntax coloring scheme by editing
html.lang
in/usr/share/gtksourceview-2.0/language-specs/
as a super user. So say you want to add HTML syntax highlighting to cfm files, you'd change this<property name="globs">*.html;*.htm</property>
(default
html.lang
) into this<property name="globs">*.html;*.htm;*.cfm</property>
You can create your own language definition files in your
$HOME
directory. Editing the gtk language specs is not recommended as it will be overriden by every gtksourceview update.Copy your language specs file to your home directory:
Then, add your custom file formats like
.cfm
to the list of extensions:That way
gedit
will use auto syntax highlighting on your custom file formats and gtk updates wont override your custom changes.This is not possible without modifying the source code of Gedit or writing a plugin to override the default. The default syntax highlighting scheme is hard-coded.
There is a conflict in the files
/usr/share/gtksourceview-3.0/language-specs/sml.lang
and/usr/share/gtksourceview-3.0/language-specs/xml.lang
Both have the
.sml
extension associated with it. To get Standard ML syntax highlighting automatically you need to erase.sml
from/usr/share/gtksourceview-3.0/language-specs/xml.lang
.