Creating Gedit Schemes

D

DevynCJohnson

Guest
Gedit is a popular text editor that many users use to write notes, create BASH and Python scripts, view configuration files, etc. Sometimes, users may want to change the way Gedit displays text. This is very useful to programmers. Gedit gives specific colors to the variables and another color for the commands. Many parts of the programming syntax has a special color. This programmer can immediately identify parts of the code by seeing the color. However, what if the programmer is color-blind or does not like the way some of the colors look? Thankfully, a simple XML file can instruct Gedit how to display programming syntaxes and plain text. This single XML file, that averages around 10kB, is called a Style Scheme or a Syntax File.

Create:

To create a style scheme, create a plain text file and type a name for the style. Remember to change the extension to "xml". Open the file using your preferred text editor. Paste this in as the first part of the file:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<style-scheme id="name" _name="Name" version="1.0">
  <author>YOUR NAME HERE</author>
  <_description>DESCRIBE YOUR SCHEME FILE BRIEFLY</_description>

The first line is the standard XML header that begins all xml files. The second line contains the name and version number of the scheme file. Replace "name" with a title that you wish to use. This name must be in all lowercase letters. The second name field should be the same title, but with any capitalization that you wish. The first created line states the ID while the second is the displayed name. The user may type anything for the version. Many programmers start the version numbering at 0.1 or 1.0.

Next, add this code:
Code:
  <!-- Global Settings -->
<style name="text" foreground="#yellow" background="#000099" />
<style name="selection" foreground="#black" background="#darkcyan" />
<style name="current-line" background="#blue" />
<style name="line-numbers" foreground="#333333" background="#cccccc" />

The first line is a comment that provides the programmer with a note concerning this block of code. This block of code sets the defaults. The name field declares an object and the next fields specify what is done with that object. For instance, the second line says the text is to be yellow (foreground). The line also says that the surrounding background of the text is to be the color generated by the hex code.

NOTE: This XML file allows users to specify colors with names (yellow) or hex values (000099). When specifying a color, put the pound sign "#" before the color indicated.

The next line controls selection which is the text selected. After that line is code that configures the color scheme of the current line. The current line is the line that contains the cursor. Notice that the foreground is not specified because it is not necessary. A user may add that field if they want. The only requirement in a line of code is the object to be modified and one field declaring the change. Lastly, "line-numbers" controls the color of the numbers in the left column that count the lines.

Once that is done, add this code block:

Code:
  <!-- Bracket Matching -->
<style name="bracket-match" foreground="#white" background="#pink" bold="true"/>
<style name="bracket-mismatch" foreground="#000000" background="#ff3300"/>

This block controls how brackets look. If a user places the cursor next to a bracket, the matching bracket will change color with the other bracket according to this code. The "bracket-mismatch" line determines how a bracket looks if there is not a matching bracket. The "bold" field will make the text bold.

NOTE: Do not set this field to false. Instead, delete the field. Otherwise, the scheme file is larger than necessary and appears more complicated.

Now for another section of code:

Code:
<!-- Comments -->
<style name="def:comment" foreground="#ff9900"/>
<style name="def:shebang" foreground="#ff9900" bold="true"/>
<style name="def:doc-comment-element" italic="true"/>

The comments section will make the comments of some programming languages have the specified look. The second line will control the comments. All shebangs (the first line of a script that declares an interpreter) will look as programmed. All doc-comment-elements will follow the rules set by the last line.

Here is a simple code block:


Code:
  <!-- Constants -->
<style name="def:constant" foreground="#green"/>

This block makes constants appear green. In computer programming, constants are variables that are permanently set.

Here is a useful line:

Code:
  <style name="def:error" foreground="#white" background="#red"/>

This line controls what programming errors look like. With this line, if I make a typo in writing a Python3 script, the error will be indicated by changing the text white and the background red.

Here is a code block that controls how a specific programming language will appear in Gedit:

Code:
<!-- XML -->
<style name="xml:doctype" foreground="#cc3300" bold="true"/>
<style name="xml:cdata-delim" foreground="#333333" bold="true"/>
<style name="xml:processing-instruction" bold="true"/>
<style name="xml:element-name" use-style="def:keyword"/>
<style name="xml:attribute-name" use-style="def:identifier"/>
<style name="xml:entity" use-style="def:special-char"/>

In this case, XML code will have this appearance. Notice the fields "use-style". This field will use previously programmed settings. For example,


Code:
use-style="def:special-char"

will use settings made by


Code:
<style name="def:special-char"

Users may custom color names with hex codes like this:


Code:
 <color name="eggshell" value="#fffff2"/>

Now, a user can type "#eggshell" instead of "#fffff2". Always remember the pound sign on color names and hex numbers.

The user can program many other programming languages and object appearances. For instance, a user could control Python by using


Code:
<style name="python:OBJECT" CHANGE="LOOK"/>

where OBJECT is the item to be changed, CHANGE is a quality to be modified, and LOOK is how it should look. Below are some random fields that can be controlled:

Code:
  <style name="def:constant"
<style name="def:character"
<style name="def:string"
<style name="def:special-char"
<style name="def:number"
<style name="def:floating-point"
<style name="def:decimal"
<style name="def:base-n-integer"
<style name="def:complex"
<style name="def:special-constant"
<style name="def:boolean"
<style name="bookmark"

It is important to know that comments are not necessary. Also, not all fields and lines shown in this article are needed, and these are not all the possible codes. Users may want to Google "hex color values" for charts of colors with the corresponding color. As for typing the color as a word, this code does not accept any word. As a result, it is best to always use hex codes. Some helpful sites that provide hex codes with the color are included below:

http://www.colorpicker.com/
http://www.color-hex.com/
http://www.colorcodehex.com/
http://www.computerhope.com/htmcolor.htm

Here is an example file:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<style-scheme id="name" _name="Name" version="0.1">
<author>Devyn Collier Johnson</author>
<_description>Demonstration</_description>
 
<!-- Global Settings -->
<style name="text" foreground="#yellow" background="#000099"/>
<style name="selection" foreground="#black" background="#darkcyan"/>
<style name="current-line" background="#blue"/>
<style name="line-numbers" foreground="#333333" background="#cccccc"/>
 
<!-- Bracket Matching -->
<style name="bracket-match" foreground="#white" background="#pink" bold="true"/>
<style name="bracket-mismatch" foreground="#000000" background="#ff3300"/>
 
<!-- Comments -->
<style name="def:comment" foreground="#ff9900"/>
<style name="def:shebang" foreground="#ff9900" bold="true"/>
<style name="def:doc-comment-element" italic="true"/>
 
<!-- Constants -->
<style name="def:constant" foreground="#green"/>
 
<!-- Others -->
<style name="def:preprocessor" foreground="#99ff66"/>
<style name="def:error" foreground="#white" background="#red"/>
<style name="def:note" background="#yellow" foreground="#black" bold="true"/>
<style name="def:underlined" italic="true" underline="true"/>
 
<!-- XML -->
<style name="xml:doctype" foreground="#cc3300" bold="true"/>
<style name="xml:cdata-delim" foreground="#333333" bold="true"/>
<style name="xml:processing-instruction" bold="true"/>
<style name="xml:element-name" use-style="def:keyword"/>
<style name="xml:attribute-name" use-style="def:identifier"/>
<style name="xml:entity" use-style="def:special-char"/>
 
<!-- Perl -->
<style name="perl:pod" foreground="#ff33ff"/>
 
<!-- Python -->
<style name="python:module-handler" use-style="def:character"/>
<style name="python:string-conversion" background="#cc66ff"/>
<style name="python:special-variable" use-style="def:constant"/>
 
<!-- Shellscript -->
<style name="sh:variable" use-style="def:type"/>
<style name="sh:variable-definition" use-style="def:identifier"/>
<style name="sh:others" use-style="def:special-constant"/>
<style name="sh:common-command" use-style="def:builtin"/>
<style name="sh:here-doc-bound" use-style="def:statement"/>
 
</style-scheme>

Import Scheme:

To load a scheme, open Gedit and click "Edit" in the menu bar. Next, click "Preferences". After that, a window should be seen. Click the "Font & Color" tab. On that screen is a list of themes. Remember that this is where you can select a new color scheme. Notice at the bottom of this box is a plus sign button. Click this button to import a new color scheme. Browse for the XML file and then click "Add Scheme".

Download Schemes:

Not only can users create schemes, but users can also download schemes. https://live.gnome.org/GtkSourceView/StyleSchemes is an excellent page that contains Gedit color schemes. Once the downloads finish, the importation is the same as with locally made style files.
 


Hi Devyn! I appreciated your article a lot and its depth. I'll pass on this link whenever I think people will benefit from it.
 
Wow! Thank you vasa1 for your interest. If you have any ideas for topics you would like me to write about just email me. [email protected]
 
Hi,

I've been going through the article a bit more ....
NOTE: This XML file allows users to specify colors with names (yellow) or hex values (000099). When specifying a color, put the pound sign "#" before the color indicated.
You may want to mention that the # sign is needed when we use the hex notation: so white will be #ffffff and black would be #000000. When colors are specified by words such as black or white, the # isn't needed and may even be incorrect.
 
Thank you for the suggestion. In my examples, I use the # sign.
 
Here is a gedit scheme that I made. Enjoy!

NOTE: change the extension to ".xml"
 

Attachments

  • Stimulant.txt
    2.2 KB · Views: 2,020
Feel free to post gedit schemes of your own. Remember to license the file under your preferred version of GPL or some other free license.
 
Not to seem too critical here, but really? XML to configure the color scheme for an editor? Does this seem a little old school to anyone else?
 
Not to seem too critical here, but really? XML to configure the color scheme for an editor? Does this seem a little old school to anyone else?

Great things never die out. The only old-school thing that is still around is Windows.:p
 
Not to seem too critical here, but really? XML to configure the color scheme for an editor? Does this seem a little old school to anyone else?
Wow, I must be old. So what are you young whipper-snappers using these days for configuration? lol
 
By the way, these are, generally speaking, GtkSourceView colour schemes, which means they work across all editors that use GtkSourceView.
 


Latest posts

Top