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:
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:
- Close Notepad++
- 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
. - Extract the
.zip
file somewhere handy. - Navigate to the Notepad++ installation folder. Mine is at
C:Program Files (x86)Notepad++
but you may have installed it somewhere else. - Rename
SciLexer.dll
asSciLexer.bak
- Copy
SciLexer.dll
from your SciTE package to your Notepad++ folder - 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:
- Settings > Style Configurator
- In the Language selector, choose
asp
- In the Style selector, choose
ASPSYBOL
- Change the Foreground color and Background color to a cool new style.
- Save & Close
Now your
.erb
file looks like this:
Go and write some nice Rails code and ignore all those dudes telling you to get a Mac.