How To Configure and Enable Syntax Highlighting in Nano Text Editor

Last Updated on: July 25, 2020

nano is one of the most popular, and friendly editor in Linux, it has several features that can boost the usability and easiness of the program.

In the guide, you’ll learn how to configure and enable syntax highlighting in nano. This way you can enable predefined syntax highlighting for programming languages, e.g Perl, Bash, Python, C, even CSS and loads more.

There are two ways to go about the configuration, you can either do a user-specific configuration where a certain user only has that specific configuration, I’ll show you how to do that in a moment or do a system-wide configuration where all your user has access to the same configuration, this is done in the /etc/nanorc file.

To do a user-specific configuration of Nano text editor, you create .nanorc in the user home directory:

This would create and open the .nanorc in your user home directory. The highlighting definitions are kept inside the /usr/share/nano/ directory, and their file names corresponding to each language. Run ls /usr/share/nano/ to view the available styles:

1. Syntax Highlight Styles

To add the syntax highlighting, open up the nanorc file: nano .nanorc

Include your preferred syntax file, e.g to add bash, I’ll do:

					

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

Go ahead and include other option. e.g PHP or Perl or whatever programming language you are working with.

Comment policy: Respectful and beneficial comments are welcome with full open hands. However, all comments are manually moderated and those that doesn't relate with what the passage is saying or offensive comments would be deleted. Thanks for understanding!

Leave a Reply

Your email address will not be published. Required fields are marked *