MATLAB syntax highlighting in Notepad++

notepad

I'm using Notepad++ to edit MATLAB .m files. It works well in most respects, except that it seems that the lexer hasn't been updated to be compatible with recent version of MATLAB.

In particular, it doesn't highlight the 'classdef', 'methods' and 'properties' keywords when using MATLAB's object-oriented features. Is there a way to update the lexer, or a way to edit it myself so that it correctly highlights these keywords?

The highlighting on the keywords 'classdef' and 'properties' should be the same as the highlighting on the keyword 'end':

enter image description here

Best Answer

Find your Notepad++ install directory (c:\Program Files or c:\Program Files (x86), typically). You need to edit the language definition file. There's two of them: an ansi file called lang.model.xml, and a unicode file called langs.xml. Most likely you are using the ansi file if you are based in US/Canada.

Open the file in Notepad++, it's a generic XML file and can use the XML syntax highlighting. Search the file for "matlab". This should take you to a block of similar to this:

<Language name="matlab" ext="m" commentLine="%" commentStart="" commentEnd="">
    <Keywords name="instre1">break case catch continue else elseif end for function global if otherwise persistent properties return switch try while</Keywords>
</Language>

Edit the <keywords> section to include the words you want higlhlighted (Classdef, properties, etc.).

Then save the file and restart Notepad++. The new syntax settings should take effect.

Related Question