Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

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

Turning on syntax highlighting in Nano is simple enough but I've just run into a non-standard issue. I have an executable Python script that doesn't have an extension.

It's part of a virtualenv environment so here's how it starts:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
share|improve this question
up vote 5 down vote accepted

You can select a specific syntax highlighting using the --syntax option, for example

nano --syntax=python myscript
share|improve this answer

Nano's default Python definition looks for one of two things an extension or a header match, as defined in /usr/share/nano/python.nanorc:

syntax "python" "\.py$"
header "^#!.*/python[-0-9._]*"

So this would match #!/bin/python. Unless you're writing something for the system, hard-coding the Python executable is a fairly bad idea... That's why env python is used these days.

The most simple way to fix Nano is to edit the definition by running sudoedit /usr/share/nano/python.nanorc and changing the header line to:

header "^#!.*python.*"

That is a lot more open.

There's actually a massively improved set of Syntax files available at the nanorc project on Github, that as well as improving other things, specifies:

header "^#!.*/(env +)?python[-0-9._]*( |$)"

It's no longer maintained but it's still a massive improvement over the defaults. It's fairly simple to install:

git clone
cd nanorc
make install

Then nano ~/.nanorc and add:

include ~/.nano/syntax/ALL.nanorc
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.