Navigation

ADS specializes in using Ruby on Rails to build advanced, scalable, database-backed web sites for organizations of all sizes. Find out more at our website.

Atlantic Dominion Solutions

While normally an OSX and TextMate user, of late I’ve had need to borrow laptop running Ubuntu 8.04, so obviously TextMate has been out of the question. While the machine is powerful enough to run Eclipse (thus RadRails) or NetBeans, I wanted something simple and quick. As it turns out, Ubuntu 8.04’s Gnome 2.22 comes with gedit, which has a couple of pretty simple plugins that will make use for Rails development a little easier, but it needs a tiny final push to round it off.

First off, pop open the gedit preferences (the Edit menu, then Preferences). For programming basics you’ll want to turn on Display line numbers on the first preferences tab (under View), otherwise when you get Rails errors you won’t be able to find where they were. The next small thing worth doing is the Rails convention of using a tab width of 2 and inserting spaces instead of tabs, which you’ll find on the Editor section - oh, you’ll also want to Enable automatic indentation otherwise you’ll drive yourself crazy. One other small thing I do here is on the Fonts & Colors section I select the Oblivion color scheme, I find the darker background with the colored text to be easier on the eyes.

The fun really begins when you go to the Plugins tab, you’ll want to activate the File Browser Pane, Indent Lines, Snippets and Tag List plugins, but for good measure I also activated Change Case, Insert Date/Time, Modelines, Sort and Spell Checker, though you can skip those if you want.

At this point you’ll be able to browse through the file pane, find your project, then double-click on the main directory to turn the file pane’s focus on just your project, making it behave kinda like TextMate. You’ll also get syntax highlighting on all .rb files, which is all controllers and models.

However, there’s still something missing - no syntax highlighting on rake, ERb or RJS files - lets fix that. The rather simple fix involves tweaking some core Gnome files in the /usr/share/gtksourceview-2.0/language-specs directory to add detection for these extra files. So, in order to do this, pop into terminal and run the following commands:

sudo nano /usr/share/gtksourceview-2.0/language-specs/ruby.lang

Once the editor shows up, after completing the usual sudo login process, go down to the line that says:

<property name="globs">*.rb</property>

and change it to:

<property name="globs">*.rb;*.rake;*.rjs</property>

Next off:

sudo nano /usr/share/gtksourceview-2.0/language-specs/html.lang

Once again, search for the line that says:

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

and change it to:

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

And that’s all there is to it. Enjoy.

Share this post

Other posts you may enjoy

You can leave a response, or trackback from your own site.

5 Responses to “ERb syntax highlighting in gedit”

On April 21st, 2008 at 5:02 am A Fresh Cup » Blog Archive » Double Shot #191 said:

[...] ERb Syntax highlighting in gedit - I don’t expect to be hacking Rails on Linux again soon, but if you do this could come in handy. [...]

On April 22nd, 2008 at 3:19 am Joslyn Esser said:

Damien, do you happen to have a set of snippets you’ve created? My partner has been writing up quite a few for himself as he prefers doing development work in a Linux environment. I had a set I used for awhile until I switched over to Mac/Textmate. I’m wondering if it would be beneficial to folks if we hosted a repository for gedit snippets similar to the collaboration going on with the TextMate bundle? Do you think there is enough users out there to make it worthwhile?

On April 22nd, 2008 at 4:56 am Damien said:

Joslyn, I haven’t written any snippets yet. I’m actually only using Linux as a desktop OS until I get an insurance refund to buy another Mac. Your repository idea does sound worthwhile, maybe you should set up a git repository somewhere? Take care, thanks for commenting.

On May 21st, 2008 at 9:40 am brent said:

this just tells gedit to use html highlights on erb/rhtml files. that is only half of correct syntax highlighting for embedded ruby files.

The other lightweight text editors that I have tried all have the same limitation. I can get ruby highlighting, and html highlighting, but for whatever reason erb is beyond the capabilities of the editor. Which is silly because php enjoys decent html/php syntax highlighting in lots of editors, and erb is essentially the same idea. You’d think, after 4 years of rhtml you would be able to find a text editor with support for it.

On May 31st, 2008 at 2:27 pm 'son said:

Thanks for the tips, they worked great except for the .erb files. Gedit treats some of my .erb files as html-like, but others it treats like matlab files [MIME type = "MATLAB script/function (text/x-matlab)]. I played around with the .lang files and the /usr/share/mime/packages/freedesktop.org.xml file, but I couldn’t figure out what I need to tweak. Any suggestions?

Leave a Reply