As a nano user I often get flack from those around me who use Vim about not having syntax highlighting. So, after taking this for some time I decided to find a way to add syntax highlighting to nano and to my surprise, it is actually already built in and simply not enabled.
Here is the simple, step-by-step process:
- Copy the /etc/nanorc file to ~/.nanorc (depending on your distribution this file may be located elsewhere)
- Open ~/.nanorc with your favorite text editor (in this case, odds are good it’ll be nano)
- Find the commented lines beginning with “include”
- Uncomment for the languages you want to have syntax highlighted in
Amazingly simple. I’m actually rather surprised it wasn’t enabled by default, but I suppose in the spirit of being a tiny text editor (hence the name) the overhead was left to an “as needed” basis.
There are a few languages not already included, but you can simply add them in yourself. I wanted to add PHP and found this link. The syntax files themselves are also editable. Allowing you to add in rules or change syntax colors.