The nano editor provides syntax highlighting for a few languages and scripts by itself. Check out /usr/share/nano/
nits@nits-excalibur:~$ ls /usr/share/nano/
asm.nanorc fortran.nanorc man.nanorc ocaml.nanorc ruby.nanorc
awk.nanorc gentoo.nanorc mgp.nanorc patch.nanorc sh.nanorc
c.nanorc groff.nanorc mutt.nanorc perl.nanorc tcl.nanorc
cmake.nanorc html.nanorc nano-menu.xpm php.nanorc tex.nanorc
css.nanorc java.nanorc nanorc.nanorc pov.nanorc xml.nanorc
debian.nanorc makefile.nanorc objc.nanorc python.nanorc
Link them to your user's nano configuration file present at ~/.nanorc
with something similiar to this line:
nits@nits-excalibur:~$ cat ~/.nanorc
include /usr/share/nano/sh.nanorc
Now, syntax highlighting is enabled in nano for whatever file you linked (You could also link multiple files)
Note: Sometimes you might get a segmentation fault
after you have edited your ~/.nanorc
file. If such an error occurs, unsetting the LANG environment variable helps. You can unset it with unset LANG
in the terminal. (Solution obtained from here)
There are also other solutions if you are not satisfied with your bash highlighting. One example of such can be found here
You can also write include /usr/share/nano/*
to the ~/.nanorc file to enable all languages to be highlighted if your nano version supports it.
man nanorc(5):
color fgcolor,bgcolor regex
For the currently defined syntax,
display all expressions matching the extended regular expression regex
with foreground color fgcolor and background color bgcolor, at least
one of which must be specified. Legal colors for foreground and
background color are: white, black, red, blue, green, yellow, magenta,
and cyan. You may use the prefix "bright" to force a stronger color
highlight for the foreground. If your terminal supports transparency,
not specifying a bgcolor tells nano to attempt to use a transparent
background.
Best Answer
You can select a specific syntax highlighting using the
--syntax
option, for example