20091006

MonoDevelop Custom Color Schemes

I have been playing with MonoDevelop 2.0 on Ubuntu on and off for a while now, but one of the things I find most annoying (other than not having ReSharper) is there is no easy way to modify the colors used for syntax highlighting. Sure, it has several pre-defined schemes you can choose from (Using Edit | Prefrences > Text Editor > Syntax Highlighting), but changing individual syntax element colors using the GUI is not possible.


The reason I find this issue annoying is that I like to have comments and strings really stand out – in our shop we avoid comments as much as possible, and string constants are kept to a minimum, so I like to be able to see them easily in the code. A few years ago, I started using “highlighter” background colors for comments and strings, and have become quite attached to them ever since.


After many attempts to find a solution on the web, I finally found all the pieces I needed to make it happen. The basic problem is that although MonoDevelop allows you to add new color schemes, the format of the scheme file is not well documented, and there are a few tricks you need to know to make it work correctly. The existing schemes are embedded resources and not stand alone files, so they can't be easily viewed for reference. Finally, I discovered this Ubuntu Forum thread that helped me find the solution. The first piece of the puzzle was discovering the color scheme XML source files in MonoDevelop's SVN tree. Now I had some samples to go by. Another useful tidbit from that thread was that the file name must end in "Style.xml" in order to work correctly. I did not actually verify that this was required, but I did it just to be safe. The rest came from a MonoDevelop Developer's Article page I stumbled across shortly thereafter. One of the important things mentioned on that page is that you need to put the color scheme XML file in the ~/.config/syntaxmodes directory (although in my Ubuntu installation it is actually ~/.config/MonoDevelop/syntaxmodes). Now I had everything I needed to start tweaking colors!

The first thing I did was download the VisualStudioStyle.xml file and renamed it to TeknynjaStyle.xml. Next I edited the file to change the name and _description attributes of the EditorStyle tag so they would not clash with the existing styles in the GUI. Finally, using the information from the MonoDevelop article and the existing examples, I modified the colors for comments and strings to get the highlighting I was looking for:

   <Style name="comment" color="black" bgColor="#ffff80"/>
<Style name="comment.doc" color="black" bgColor="#ff8040"/>
<Style name="comment.tag.doc" color="black" bgColor="#ff8040"/>

<Style name="text.preprocessor" color="purple"/>
<Style name="text.markup" color="skyblue"/>

<Style name="constant" color="black"/>
<Style name="constant.language" color="keyword-blue"/>

<Style name="string" color="black" bgColor="#80ff80"/>
<Style name="string.single" color="black" bgColor="#80ff80"/>
<Style name="string.double" color="black" bgColor="#80ff80"/>
<Style name="string.other" color="black" bgColor="#80ff80"/>

<Style name="keyword" color="keyword-blue">
<Style name="type" color="#004080"/>
</Style>

I found the "bgColor" attribute by looking in one of the other color scheme files. Then I copied my customized color scheme file to ~/.config/MonoDevelop/syntaxmodes, restarted MonoDevelop, and selected my color scheme. I was able to tweak the colors by editing the XML file and restarting MonoDevelop until I achieved the scheme I was looking for. Finally I had the highlighting I was used to in Visual Studio, and along with modifying some of my commonly used key bindings, I was able to make MonoDevelop feel a little more like "home".

4 comments:

Michael Hutchinson said...

Thanks for the article! You're correct that the location should be ~/.config/MonoDevelop/syntaxmodes - I've fixed it in the docs.

teknynja said...

Michael - It looks like if I had stumbled across your list posting before I would have figured this out much sooner! Not sure how I missed it before, but thanks!

Anonymous said...

To anyone looking, here is the new home of the build-in styles:

https://github.com/mono/monodevelop/tree/master/main/src/core/Mono.Texteditor/Styles

Anonymous said...

I discovered that in addition to weight="bold" and weight="italic" the combination weight="bold-italic" works.

 
Template design by Amanda @ Blogger Buster