cmacosterminalsyntax-highlightingnano

Nano syntax highlighting in Mac OS X 10.7 (Lion)?


How to enable syntax highlighting for nano in Mac OS X 10.7 (Lion)?

According to what I found so far on Google is that it has got to do with /.nanorc file. I have no idea how to get it or make it?

When I try to find nano in my terminal this is what I get:

Notra:~ Sukhvir$ whereis nano
/usr/bin/nano

According to what I found on Internet this is the file I need to edit:

~/.nanorc

But how do I get to it/how to open it/if I don't have it then how to make it?

I am a bit new to programming folks, so step-by-step instructions will be highly appreciated.

I need it for C mainly.

According to what I found online, I have to paste this into the .nanorc file:

include "/usr/share/nano/nanorc.nanorc"
include "/usr/share/nano/c.nanorc"

However this will not work because there is no such directory as /usr/share/nano.

I also just did ls /usr/share/ and according to the results there is no nano in that directory. Is this a Mac OS X 10.7 (Lion) issue or an issue on my Mac?


Solution

  • Here are some steps to help you out.

    1. Create a new directory in /usr/local/share/ called 'nano' like this:

    mkdir /usr/local/share/nano

    1. Now, using nano, make a nano resource file for your C syntax like this:

    nano /usr/local/share/nano/c.nanorc`

    1. Now put your C code highlighting in this file and save it. Here is a link to some possible C syntax highlighting:

    http://code.google.com/p/nanosyntax/source/browse/trunk/syntax-nanorc/c.nanorc

    1. Save that file and now open your user’s nano resource file by typing:

    nano ~/.nanorc

    1. In this file, add a reference to the c.nanorc file you just made like this:

    include "/usr/local/share/nano/c.nanorc"

    1. Save your user resource file.

    Now, when you open up C files, you should see syntax highlighting. You can add additional syntax highlighting for different types of files using the same method. Just add more lines to your ~/.nanorc file.

    Note that depending on your user permissions, you may have to precede some of the above commands with sudo and then enter your root password.