Nano – Shortcuts, syntax highlight and .nanorc config file – pt2

And now, let’s look at the .nanorc file.

Here, i’ll go through the .nanorc config file, try to explain parts of it and set the syntax highlight on.
See the first part for shortcuts .

You can use the sample nanorc from /usr/share/nano/ , a copy from /etc/nanorc, or even from the sample nanorc in /usr/share/doc/nano/examples/. A blank one is just fine too.

If in doubt, do nano -V to see if it was compiled with the proper flags. here’s mine:

nano -V
GNU nano version 2.0.4 (compiled 12:23:22, Jun 22 2007)
Email: Web:
Compiled options: –disable-wrapping-as-root –enable-color –enable-multibuffer –enable-nanorc –enable-utf8

auto indent: (Meta-I) to toggle
set autoindent
so the next line starts after the same number of spaces /tabs as the previous line.
nano doesn’t know how to properly indent code lines.

set brackets ""')>]}"
to be able to justify paragraphs after one of those characters.
Use ctrl+j to justify the paragraph, meta+j to justify all the file, and ctrl+u to undo the justification

Match Brackets
set matchbrackets "(]}"
use meta+altgr+9 (i.e meta+] ) to switch between the matching brackets

Remove empty first line (Meta-O) to toggle
set morespace
as said in the manual: “Use the blank line below the titlebar as extra editing space.”

Hide the help shortcuts at the bottom ( Meta-X )
set nohelp
“Don’t display the help lists at the bottom of the screen.”

Mouse support (Meta-M)
set mouse
Well, i’m still giving a 2nd change, because it’s not that useful. With it enable, nano will allow you to move the cursor, set a mark (see below) and use the helpful shortcut list at the bottom. To use the mark, double click and drag, or double click and move the cursor with the arrow keys. You can them, cut ( ctrl+k ), and to paste it, ctrl+u. Those are the good things. the bad, it won’t let you middle click and thus paste things into the current position inside the editor. Also, copying text with the mouse to use outside the editor is disabled. So basicly, we get a more featured editor, but with less integration with the surrounding environment. Completely useless in text mode.
If only it had the ability to scroll up/down with the mouse wheel…

Allow multibuffer (Meta-F)
set multibuffer
This is actually extremely useful. If this option isn’t active, the crtl+r (read file)
just adds the file into the same buffer. With it, it opens a new buffer! You can cicle through the buffers with Meta+< and Meta+>

set smooth
Text will scroll line-by-line, instead of the usual chunk-by-chunk behaviour.

Save automatically on exit (without prompt)
set tempfile
Although this might seen a time-saver, beware to not enable this on a normal user. When enabled, if nano opens a file which the user doesn’t have permission and modifies it, nano won’t ask for the option to not save it, and thus you’ll be stuck inside nano forever! :P
( you can ofc, save it on a proper directory:/home/you/thatevilfile )
Aparently, the bug is said to be fixed on the version2, but i guess not quite. i’ve to check upon that…

Next the include files for the syntax highlighting. just comment the include lines you’ll think wont be useful.
i’m using this ones:

## Nanorc files
include "/usr/share/nano/nanorc.nanorc"

## C/C++
include “/usr/share/nano/c.nanorc”

include “/usr/share/nano/html.nanorc”

## Patch files
include “/usr/share/nano/patch.nanorc”

## Manpages
include “/usr/share/nano/man.nanorc”

## Groff
include “/usr/share/nano/groff.nanorc”

## Perl
include “/usr/share/nano/perl.nanorc”

## Python
include “/usr/share/nano/python.nanorc”

## Bourne shell scripts
include “/usr/share/nano/sh.nanorc”

include “/usr/share/nano/gentoo.nanorc”

## Syntax Highlight Pack
## CSS
include “/usr/share/nano/css.nanorc”

## php
include “/usr/share/nano/php.nanorc”

## makefile .am
include “/usr/share/nano/gentoo.nanorc”

More syntax higlight files:
update link to syntax Highlight pack on github.
syntax Highlight pack
they are a collection taken from the gentoo foruns.

I’ve took the following 2 from more Syntax highlighting(dead link as of 2012)
This is useful for those debian people.

## syntax highlighting for /etc/apt/sources.list
## syntax "apt/sources.list" "sources\.list(\.old|~)?$"
# component
color brightmagenta "^deb(-src)? ((http|file|ftp):/[^ ]+|cdrom:\[[^\]]+\]/|cdrom:\[[a-zA-Z0-9\._-\(\) ]+\]/) [^ ]+ .+$"
# distribution
color brightred "^deb(-src)? ((http|file|ftp):/[^ ]+|cdrom:\[[^\]]+\]/|cdrom:\[[a-zA-Z0-9\._-\(\) ]+\]/) [^ ]+"
color brightgreen "(http|file|ftp):/[^ ]+"
# cdroms
# [^\]] does not work...
color brightgreen "cdrom:\[[a-zA-Z0-9\._-\(\) ]+\]/"
# deb / deb-src
color cyan "^deb"
color brightblue "^deb-src"
# comments
color brightyellow "#.*"

config files (.ini)

# ini highlighting
syntax "ini" "\.ini(\.old|~)?$"
# values
color brightred "=.*$"
# equal sign
color green "="
# numbers
color brightblue "-?[0-9\.]+\s*($|;)"
color brightmagenta "ON|OFF|On|Off|on|off\s*($|;)"
# sections
color brightcyan "^\s*\[.*\]"
# keys
color cyan "^\s*[a-zA-Z0-9_\.]+"
# comments
color brightyellow ";.*$"

That’s all for now.. Hope you’ll find it useful to bring more “shiningness” to your nano.

Published by Pedro Carvalho

Webdev, sysadmin, webdesigner and SEO guy with a passion for the GNU/Linux and all that orbits around it.

20 thoughts on “Nano – Shortcuts, syntax highlight and .nanorc config file – pt2

  1. Very nice! i prefer nano over vi since i always fuckup in vi heh. I recently read about syntax highlightning in nano, and most of the .nanorc files were already installed, but a few were missing, such as css.nanorc but not any more :)


  2. Hi I’m a complete and utter newb at using nano. All I know is coming from blogs like this one, and forums from the net. Can you please take a moment to walk me through the steps on how to enable syntax lighting in laymen terms?
    Like you put ” Next the include files for the sintax highlighting. just comment the include lines you’ll think will be useful.” Ummmm, how do I comment the include lines? Do you mean remove the ‘//’? Do I put all this inside the terminal? SOrry

    1. Hello there Sam!
      So let’s do this together then!
      Actually that line has a type! 2 years it has passed! thank you calling me to attention. It should read:
      “Next the include files for the sintax highlighting. Just comment the include lines you’ll think it wont be useful.”

      And you can comment with putting a “#” at the beggining of the line.

      So step by step:
      1. get the syntax highlight packs
      2. extract them to a directory of your choice
      3. on your ~/.nanorc include the ones you need
      ex: if you have lolcode.nanorc in “~/.nano/syntaxhightlight/lolcode.nanorc”
      you can include it with in your .nanorc like this:

      include “~/.nano/syntaxhighlight/lolcode.nanorc”

      if dont want it just:

      #include “~/.nano/syntaxhighlight/lolcode.nanorc”

      4. you’re done!

  3. Hey there! This post could not be written any better!
    Reading this post reminds me of my previous room mate! He always kept chatting about this.
    I will forward this post to him. Pretty sure he will have a good read.
    Thank you for sharing!

  4. Thanks for the syntax highlighting tips !
    Do you know how the set the shortcuts to the “Windows” style ? as CTRL+C to copy, CTRL+V to paste, SHIFT+arrow to highlight ?

    1. why yes! i use it like this: (emacs style)
      unbind ^D all
      bind ^D searchagain all

      unbind ^G main
      bind ^G gotoline main

      unbind ^_ all
      bind ^_ undo all

      unbind ^U all
      bind ^Y uncut all

      unbind ^S all
      bind ^S writeout all

      unbind ^^ all
      unbind M-Space all
      unbind ^Space all
      unbind M-W all

      bind ^Space mark all
      bind M-W copytext all

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s