The default version of nano that is installed on a mac most likely does not support syntax highlighting. To check your version run:

1
nano --version

You will need to upgrade it using a version from Homebrew. If you don’t have Homebrew, then you can install it easily.

Think of Homebrew like a command line based AppStore.

To install Homebrew, run the following command from Terminal

1
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

More info about installing Homebrew at their site.

After installation, close & reopen your Terminal. Now if you run nano --version you should see that your version of nano is upgraded. This newer version of nano supports colors and syntax highlighting.

You now need to set the syntax highlighting colors for various languages. Fortunately, there are many users who’ve created these rules and you can quickly download & use one of these “rulesets”.

You can download one such ruleset created by scopatz at Github using this command:

1
curl https://raw.githubusercontent.com/scopatz/nanorc/master/install.sh | sh

Run this from your user’s root folder to download and set the rules for the user. The command will download the rules for various languages and save it to a folder called .nano. It will also create the .nanorc which refers to this list of rules in .nano folder.

Close & reopen Terminal again to ensure that nano now uses these rules.

Open an HTML file, for example, and you’ll notice that the HTML tags are now color-coded.