How To Enable Syntax Highlighting for Nano In Windows?

Posted on

Problem :

I am a huge fan of the nano editor, but I can’t get the syntax highlighting to work in the windows version. Is it possible to have syntax highlighting in windows?

Solution :

The selected answer by James Baxter is incorrect.

In order to enable syntax highlighting for nano in Cygwin, you will need to create ~/.nanorc, which is the file that nano looks for when loading syntax highlighting.

In this file you should include whatever include statements containing paths to the syntax highlighting files, which are usually located in /usr/share/nano.

The contents of my ~/.nanorc:

include /usr/share/nano/asm.nanorc
include /usr/share/nano/autoconf.nanorc
include /usr/share/nano/awk.nanorc
include /usr/share/nano/c.nanorc
include /usr/share/nano/changelog.nanorc
include /usr/share/nano/cmake.nanorc
include /usr/share/nano/css.nanorc
include /usr/share/nano/debian.nanorc
include /usr/share/nano/default.nanorc
include /usr/share/nano/elisp.nanorc
include /usr/share/nano/fortran.nanorc
include /usr/share/nano/gentoo.nanorc
include /usr/share/nano/go.nanorc
include /usr/share/nano/groff.nanorc
include /usr/share/nano/guile.nanorc
include /usr/share/nano/html.nanorc
include /usr/share/nano/java.nanorc
include /usr/share/nano/javascript.nanorc
include /usr/share/nano/json.nanorc
include /usr/share/nano/lua.nanorc
include /usr/share/nano/makefile.nanorc
include /usr/share/nano/man.nanorc
include /usr/share/nano/mgp.nanorc
include /usr/share/nano/mutt.nanorc
include /usr/share/nano/nanorc.nanorc
include /usr/share/nano/nftables.nanorc
include /usr/share/nano/objc.nanorc
include /usr/share/nano/ocaml.nanorc
include /usr/share/nano/patch.nanorc
include /usr/share/nano/perl.nanorc
include /usr/share/nano/php.nanorc
include /usr/share/nano/po.nanorc
include /usr/share/nano/postgresql.nanorc
include /usr/share/nano/pov.nanorc
include /usr/share/nano/python.nanorc
include /usr/share/nano/ruby.nanorc
include /usr/share/nano/rust.nanorc
include /usr/share/nano/sh.nanorc
include /usr/share/nano/spec.nanorc
include /usr/share/nano/tcl.nanorc
include /usr/share/nano/tex.nanorc
include /usr/share/nano/texinfo.nanorc
include /usr/share/nano/xml.nanorc

The easiest way to do this is a simple one-liner:

ls -1 /usr/share/nano | sed 's@^@include /usr/share/nano/@' > ~/.nanorc

If your /usr/share/nano does not already contain any .nanorc files, just download them from the Git repo.

The issue is that nobody tell you that the native Windows API version of Nano, require you to use POSIX paths for the syntax highlighter files *.nanorc in your include statement in .nanorc.

Edit your .nanorc in C:Users<username>.nanorc and make sure the import lines reads something like this:

#include "C:nanonanorc*.nanorc"     # Windows paths does NOT work!
include "/nano/nanorc/*.nanorc"        # This works!

Leave a Reply

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