How do I enable syntax highlighting in nano?

Can nano do syntax highlighting like gedit and vim? How can I enable it? I need at least bash and python syntax highlights.


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, ${XDG_CONFIG_HOME}/nano/nanorc, or ~/.config/nano/nanorc, whichever is encountered first) 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)

screenshot of syntax highlighting

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.


Yes you can, however the default syntax definitions are quite poor and incomplete. I'm maintaining a more accurate set of definitions here, for anyone who finds them useful.

To install, run:

git clone https://github.com/scopatz/nanorc.git
cd nanorc
make install

Add these lines to the ~/.nanorc

include ~/.nano/syntax/html.nanorc
include ~/.nano/syntax/css.nanorc
include ~/.nano/syntax/php.nanorc
include ~/.nano/syntax/ALL.nanorc

Specify the ones you want to have colorizing for, and you will have to tune these colors to your preferences. The ALL.nanorc describes features for all yet unclassified files. These are the tools you need to get started, not the end polished product.