Chris Tankersley

· PHP Jack of All Trades ·

Enabled Syntax Highlighting in nano

I spend a lot of the day in nano. It's a quick and easy way to edit text from the command line in Linux, and my editor of choice. I've started programming in Python and use nano when I need to do a quick edit. To help me find what I needed, I enabled syntax highlighting.

NOTE: The following instructions set up the nano settings for your user. If you want to change the settings for everyone, you will need to edit /etc/nanorc instead of ~/.nanorc

If you have nano already installed, the first thing you need to do is find the default nanorc file. In Ubuntu, I found this in /etc/nanorc (this is a global default file for all users). To find yours, search for 'nanorc' or 'nanorc.sample.gz'. Copy or exact the file into your home directory and name it '.nanorc'.

  • Copy to your home directory: cp /etc/nanorc ~/.nanorc

  • Extract sample to home directory: zcat /usr/doc/nano-x.x.x/nanorc.sample.gz >~/.nanorc

Open up the file in nano. By default all of the options are commented out. Go through the file and uncomment what settings you want to turn on. Since Python is whitespace-dependant I also enabled auto-indentation.

The file should be fairly well commented. Search for Python or what ever language you want to enable syntax highlighting for and uncomment it. Some installations will have the full code that you need to uncomment or just a link to the file that contains the actual highlighting rules.

Once you are finished uncommenting what you need, save and exit the file. Test it by opening an appropriate file and everything should be color-coded!


Categories: Programming

Tags: Coding