Syntax Highlighting in Nano

When I’m messing around with config files on the command line my editor of choice is Nano. It’s simple, fast and pretty much straight forward. You don’t have to learn any commands and can use keyboard shortcuts just like in GUI programs.


Today I had a look on the project website and saw that there are tons of settings which I really missed before. Just have a look into your /etc/nanorc for a default config file with all settings and their default values. Here are those I like most:

Syntax Highlighting

Yes! Nano supports syntax highlighting! And I never knew it, but heck - it’s never to late. Not for neat features like this one, though I really wonder why this is not activated by default…

In the aforementioned /etc/nanorc are already some default languages which just wait to be commented out. You might also want to have a look into /usr/share/nano, there are some languages you can include in your nanorc file with:

include “/usr/share/nano/html.nanorc”

Additionally I found some more languages on the gentoo wiki. And of course I’ll post any homebrew syntax files in my Snippets section.

my syntax highlighting files


Want to comment? Send me an email!

Comment by ElDiablo (not verified) (2014-02-28 14:44:00)

You are my hero :)

Comment by yummibunny (not verified) (2014-02-12 02:05:00)

thx for the .ini file :)

Comment by Anonymous (not verified) (2013-05-03 01:28:00)

Was looking at nanorc, reading, and came across the git repository below. It is really cool how the author handles the highlighting to keep it consistent across languages. He also has nice key bindings.

Comment by Ölbaum (not verified) (2013-01-28 15:42:00)

Yes, nano supports syntax highlighting and it’s retarded. I love having all my variables unappear in white over my white background.

Comment by Huh (not verified) (2013-03-25 06:38:00)

Yea what the hell is that about? Something’s it decides should be red, some white, totally random as far as I can tell. Anyone have a fix for this?

Comment by Godric (not verified) (2009-10-18 14:16:00)

Well, two keystrokes, one forth and one back. ;-D

Milian: thx for .ini syntax file. ;-)

Comment by Raven Morris (not verified) (2009-08-14 03:50:00)

I always knew that Nano could do syntax highlighting, or at least I had heard that it could. I decided to go try it out today, thanks for the article.

You should be using :x instead of :wq … Save yourself one keystroke. :-P

Comment by Jon (not verified) (2009-08-04 23:44:00)

Bloody hell nano supports syntax highlighting? Maybe I’ll loathe it a little less on those machines where I’m not allowed to put export EDITOR=vi in root’s .bashrc once I’ve edited that nanorc. I’ll never stop myself hitting :wq though, then growling as I have to go back and delete it before pressing Ctrl X

Published on August 04, 2009.