Nano is a popular, user-friendly text editor which can be ran in a shell, without the need of an X Server. It can be very useful especially for editing text files (like configuration files or scripts) in a fast manner, being faster than more advanced, graphical text editors.
Nano has syntax highlighting support for programming languages, which is disabled by default. However, Nano provides default rules for several languages like Perl, Python, or C, to name a few. These highlighting definitions are kept inside the /usr/share/nano/ directory, and for each language there is available a file with rules.
For example, ls /usr/share/nano will output the following on my system, which has Nano 2.0.7 installed:
$ ls /usr/share/nano/
asm.nanorc groff.nanorc java.nanorc mutt.nanorc nanorc.nanorc perl.nanorc python.nanorc sh.nanorc
c.nanorc html.nanorc man.nanorc nano-menu.xpm patch.nanorc pov.nanorc ruby.nanorc tex.nanorc
These are default syntax highlighting rules for several languages, like Java, Perl, Python, Bash, C, HTML or Ruby.
In order to enable syntax highlighting in Nano based on one of these files, edit the ~/.nanorc file, where ~ is your home directory. Notice that you will have to create this file if it doesn't already exist. Then add lines to it in this fashion:
include "/usr/share/nano/c.nanorc"
include "/usr/share/nano/perl.nanorc"
include "/usr/share/nano/sh.nanorc"
include "/usr/share/nano/html.nanorc"
And so on for each language you want to have syntax highlighting enabled. Those four lines will include the files c.nanorc, perl.nanorc, sh.nanorc and html.nanorc, which will define highlighting rules for C, Perl, Bash and HTML respectively. This can also be accomplished by copying the contents of one of those files directly into ~/.nanorc. For example:
cat /usr/share/nano/c.nanorc >> ~/.nanorc
The above command will append the contents of /usr/share/nano/c.nanorc at the end of ~/.nanorc, enabling syntax highlighting for C. You can also search on Google for other rules, if the default colours don't fit well.
Notice: This tutorial is a later, revised version of the tutorial which I initially published here.Source URL: http://ashesgarrett.blogspot.com/2009/04/how-to-enable-syntax-highlighting-in.html
Visit ashes garrett for Daily Updated Hairstyles Collection
Nano has syntax highlighting support for programming languages, which is disabled by default. However, Nano provides default rules for several languages like Perl, Python, or C, to name a few. These highlighting definitions are kept inside the /usr/share/nano/ directory, and for each language there is available a file with rules.
For example, ls /usr/share/nano will output the following on my system, which has Nano 2.0.7 installed:
$ ls /usr/share/nano/
asm.nanorc groff.nanorc java.nanorc mutt.nanorc nanorc.nanorc perl.nanorc python.nanorc sh.nanorc
c.nanorc html.nanorc man.nanorc nano-menu.xpm patch.nanorc pov.nanorc ruby.nanorc tex.nanorc
These are default syntax highlighting rules for several languages, like Java, Perl, Python, Bash, C, HTML or Ruby.
In order to enable syntax highlighting in Nano based on one of these files, edit the ~/.nanorc file, where ~ is your home directory. Notice that you will have to create this file if it doesn't already exist. Then add lines to it in this fashion:
include "/usr/share/nano/c.nanorc"
include "/usr/share/nano/perl.nanorc"
include "/usr/share/nano/sh.nanorc"
include "/usr/share/nano/html.nanorc"
And so on for each language you want to have syntax highlighting enabled. Those four lines will include the files c.nanorc, perl.nanorc, sh.nanorc and html.nanorc, which will define highlighting rules for C, Perl, Bash and HTML respectively. This can also be accomplished by copying the contents of one of those files directly into ~/.nanorc. For example:
cat /usr/share/nano/c.nanorc >> ~/.nanorc
The above command will append the contents of /usr/share/nano/c.nanorc at the end of ~/.nanorc, enabling syntax highlighting for C. You can also search on Google for other rules, if the default colours don't fit well.
Syntax highlighting for C in Nano
Notice: This tutorial is a later, revised version of the tutorial which I initially published here.Source URL: http://ashesgarrett.blogspot.com/2009/04/how-to-enable-syntax-highlighting-in.html
Visit ashes garrett for Daily Updated Hairstyles Collection