How To: Syntax highlight GLSL shaders in Gedit

GLSL shaders share a lot in common with the C language, and Gedit can syntax highlight C/C++ and a host of other languages – so why not GLSL shaders? Here’s a simple way to make it happen…

1.) Gedit uses gtksourceview for its syntax highlighting rules – so find out where that’s located on your distro with the following:

locate gtksourceview | grep /c.lang

Once you’ve got the location of the c.lang file, navigate there in the bash (on Ubuntu it’s in /usr/share/gtksourceview-2.0/language-specs).

2.) Make a copy of the c.lang file in case you accidentally stuff it up (optional, but better safe than sorry):

sudo cp c.lang c.lang.ORIG

3.) Open the file with your text editor of choice and modify the c.lang file to add in additional file extensions which should be syntax highlighted as per the c.lang definitions:

gksudo gedit ./c.lang

A couple of lines into the file (after the comments at the top) you’ll see the following:

<property name="globs">*.c;</property>

Assuming you’re ending your vertex shaders with .vp and your fragment shaders with .fp (if you’re using .vert and .frag or such just substitute appropriately), change the line to read:

<property name="globs">*.c;*.vp;*.fp</property>

Save it, close gedit, and open a .vp or .fp file with Gedit – syntax highlighty goodness is rightfully yours. Of course, this is normal C highlighting, not true GLSL highlighting – but it’s a good start.

If you wanted to add things like vec3, uniform etc. then you can find the following sections in the c.lang file and add ’em in yourself:

<context id="keywords" style-ref="keyword" class="keyword">
<context id="types" style-ref="type" class="type">


2 thoughts on “How To: Syntax highlight GLSL shaders in Gedit”

  1. if you give your file extensions like .glslv or .glslf , you will have syntax highlighting for glsl.

    Or you can edit glsl.lang

    1. Thanks for the tip, I don’t think gedit shipped with GLSL highlighting at all back when I wrote this in 2011 – but I didn’t know it had been added either.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.