27

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?

4 Answers4

21

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>

Kris Harper
  • 13,705
jdup
  • 226
17

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:

$ cp /usr/share/gtksourceview-3.0/language-specs/html.lang ~/.local/share/gtksourceview-3.0/language-specs/

Then, add your custom file formats like .cfm to the list of extensions:

<property name="globs">*.html;*.htm;*.cfm</property>

That way gedit will use auto syntax highlighting on your custom file formats and gtk updates wont override your custom changes.

q9f
  • 1,261
  • 4
  • 18
  • 30
9

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.

Lucio
  • 19,191
  • 32
  • 112
  • 191
ændrük
  • 78,496
0

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.