read

If you’re one of the tiny band of people developing Ruby or Rails code on Windows, then you might have tried editing .erb files with Notepad++. In general, Notepad++ is a very nice little text editor. It’s my only IDE. But it’s not very good at .erb files. Here’s an example:

Without SciLexerYuk.

There’s two problems here. One is the godawful color scheme. But other is more serious: Notepad++ fails to recognise the quoted text within a pair of <% ... %> braces.

The cause of this is the parsing engine built into Notepad++: Scintilla. Scintilla thinks that <% ... %> braces indicate ASP code, and therefore a single quote indicates the start of a comment. The “comment” includes the closing brace at the end of the line, so the rest of the document is parsed as an ASP comment.

I’m using Notepad++ 5.9.3, the latest version at the time of writing. This uses the Scintilla SciLexer.dll version 2.2.7. More recent versions of the dll don’t have this problem, so the solution is straightforward: replace Notepad++’s dll with a more recent one. Here’s how to do it step by step:

  1. Close Notepad++
  2. Download the Scintilla text editor, SciTE. The latest version at the time of writing is here: https://sourceforge.net/projects/scintilla/files/SciTE/2.29/ and the file you want is wscite229.zip.
  3. Extract the .zip file somewhere handy.
  4. Navigate to the Notepad++ installation folder. Mine is at C:Program Files (x86)Notepad++ but you may have installed it somewhere else.
  5. Rename SciLexer.dll as SciLexer.bak
  6. Copy SciLexer.dll from your SciTE package to your Notepad++ folder
  7. Restart Notepad++

You will be asked by Windows if you really want to mess around in the Program Files folder. Yes, you do.

Hurrah! Now the .erb braces are parsed correctly:

But it's still a naff colour scheme.

If you look in Notepad++’s Style Configurator, you won’t find anything in Global Styles or HTML to change this. There isn’t an Erb language specification. So how do we change the colour of the braces?

Notepad still thinks they are ASP braces. The style it is rendering is the ASPSYBOL style in the asp language configuration. Here’s how to change it:

  1. Settings > Style Configurator
  2. In the Language selector, choose asp
  3. In the Style selector, choose ASPSYBOL
  4. Change the Foreground color and Background color to a cool new style.
  5. Save & Close

Now your .erb file looks like this:

Win!

Go and write some nice Rails code and ignore all those dudes telling you to get a Mac.