Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
Thanks very much for the syntax files in the git repo, I use this on all my servers now... keep up the good work matey !!! – user326219 Sep 12 '14 at 15:23
@TheGene Comment and thank on the answer. The repo is credited to him, not me, the one asking the question. – Oxwivi Sep 15 '14 at 11:45

10 Answers 10

up vote 99 down vote accepted

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)

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 and making it just a few bytes smaller...(there are no disadvantages!).

share|improve this answer
Those lines are uncommented in /etc/nanorc - are the global settings being overwritten by ~/.nanorc? How do I disable .nanorc? – Oxwivi Dec 23 '11 at 16:31
Oh wait, I don't even have a ~/.nanorc file. – Oxwivi Dec 23 '11 at 16:33
The global settings (in /etc) provide settings for all users. The ~/.nanorc provides additional settings for your user-profile. To disable your '~/.nanorc' you can just rename it or delete it. (Edit after the second comment), you can create one by touch ~/.nanorc – Nitin Venkatesh Dec 23 '11 at 16:34
Wait, wait, how come the global setting with all the include lines not enabling syntax highlights even though I have not .nanorc? – Oxwivi Dec 23 '11 at 16:53
include /usr/share/nano/* is not working – Jarek Jakubowski May 16 at 8:23

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
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.

share|improve this answer
Thanks for keeping those nice syntax definitions in GitHub. – Rubens Mariuzzo Nov 13 '12 at 2:43
My *.js files weren't working...edited /etc/nanorc to remove any other syntax includes as per the FAQ…. ♥ Nano ♥ nanorc – Carlton Aug 6 '14 at 12:27
I just installed your syntax defs on Mac OSX. There's only one thing I'd note, which is the black colour of the open-bracket in python gets lost against the black background of my terminal – Tom Busby Aug 27 '14 at 14:25
this is REALLY awesome, thanks!! – Kevin Duke Dec 8 '14 at 3:03
Actually there is a problem, some of the colored text is black! If our terminal background is black, these words are invisible! – Kevin Duke Dec 8 '14 at 3:20

I used this command to quickly enable all available languages.

find /usr/share/nano/ -iname "*.nanorc" -exec echo include {} \; >> ~/.nanorc

As mentioned in other answers, /usr/share/nano/ contains the definitions for different languages.

$ ls /usr/share/nano
asm.nanorc     fortran.nanorc   man-html       ocaml.nanorc   ruby.nanorc
awk.nanorc     gentoo.nanorc    man.nanorc     patch.nanorc   sh.nanorc
cmake.nanorc   groff.nanorc     mgp.nanorc     perl.nanorc    tcl.nanorc
c.nanorc       html.nanorc      mutt.nanorc    php.nanorc     tex.nanorc
css.nanorc     java.nanorc      nanorc.nanorc  pov.nanorc     xml.nanorc
debian.nanorc  makefile.nanorc  objc.nanorc    python.nanorc

Also mentioned, to enable highlighting for a language, you add include and the path to the language definition you want to enable to your ~/.nanorc file. So, for example, to enable C/C++ you would add this line.

include /usr/share/nano/c.nanorc

The find command searches for files or directories within the specified directory.

  • The -iname flag tells it to only look for files with a name that ends with .nanorc.
  • The -exec flags defines a command to execute on each file found.
  • The {} gets replaced with the file name.
  • \; is used to signify the end of the command to execute to the find command.
  • Lastly, >> ~/.nanorc causes the output to be appended to your ~/.nanorc file.
share|improve this answer
thanks for the auto add snippet ;) – schlenger Dec 15 '15 at 15:01
great tip and explanation, thanks a lot man! ;) – daveoncode May 14 at 17:02

I have some nano syntax highlighting at my github.

There are live example screenshots for html and php:

enter image description here


enter image description here

share|improve this answer
wget -r -nH --cut-dirs=3 --no-parent --reject="index.html*" -P ~/.nano-syntax
for i in `ls --color=never -1 ~/.nano-syntax/*.nanorc` ; do echo "include $i" >> ~/.nanorc ; done
share|improve this answer
It would be helpful if you could explain why this is a useful answer for newer users. What is the command doing? What does it change? Randomly suggesting to run a command line is not helpful. – Kevin Bowen Jun 28 '13 at 3:10

I found syntax highlighting for js here.

I appended it into my user file at ~/.nanorc

However to get a file into which I could append, I had to first copy from /usr/share/nano/nanorc.nanorc to my local folder first as ~/.nanorc.

share|improve this answer

The most complete and up to date syntax hilighters for nano are maintained here.

To install all highlighters for your user just run:

cd /tmp
git clone
cd nano-highlight/
make install
echo "include ~/.nano/syntax/ALL.nanorc" >> ~/.nanorc
share|improve this answer
The solution is good, but I would use an other folder for git clone. The content otf the /tmp folder will be deleted on every system start and therefore you could never run a git pull. – A.B. Jul 30 '15 at 8:00
Your language tag is wrong. js isn't bash or shell-script and I have placed the link behind the word here. Where is the problem? – A.B. Jul 30 '15 at 8:19

I just made this script to add the colours to nano: But of course you got to have the color codes in /usr/share/nano for this to work. If there are errors: just manually edit the ~/.nanorc file and remove the lines that give the errors.


for i in `ls /usr/share/nano`
    echo "include /usr/share/nano/$i" >> ~/.nanorc
share|improve this answer

You can use this to include all: (add this to ~/nanorc file)

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

Happy coding !

share|improve this answer

For those who are having trouble after following the instructions above, also check if you have duplicate definitions. These will disable all syntax highlighting for all files. I ran into this after adding a nanorc.nanorc file, and not realising that my ~/.nanorc already had an identical section, i.e.:

## Here is an example for nanorc files.
syntax "nanorc" "\.?nanorc$"
## Possible errors and parameters
icolor brightwhite "^[[:space:]]*((un)?set|include|syntax|i?color).*$"
## Keywords
icolor brightgreen "^[[:space:]]*(set|unset)[[:space:]]+(autoindent|backup|$
icolor green "^[[:space:]]*(set|unset|include|syntax)\>"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.