The GNU of Life, the Universe and Everything

June 23, 2007

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

Filed under: nano — Tags: , , , , — Pedro Carvalho @ 7:36 pm

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: nano@nano-editor.org Web: http://www.nano-editor.org/
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.

brackets:
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.”

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

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 permition 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 sintax 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”

## HTML
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: syntax Highlight pack
they are a colection 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\._-\(\) ]+\]/) [^ ]+"
# URI
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*($|;)"
# ON/OFF
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.

About these ads

17 Comments »

  1. [...] So, that might be enough for your daily tasks. See the next part for more nano’s details. Part 2: nanorc and syntax hightlight [...]

    Pingback by Nano - Shortcuts, syntax highlight and nanorc config file - pt1 « The GNU of Life, the Universe and Everything — June 23, 2007 @ 8:02 pm

  2. I just learned about the highlighting and such, too. Your post really helps, thanks!

    :P

    Comment by meathive — January 26, 2008 @ 3:38 pm

  3. i’m glad it can help you! have fun with nano!

    Comment by Pedro Carvalho — January 26, 2008 @ 7:03 pm

  4. Great..
    Just discovered nano syntax highlighting..
    Thanks

    Comment by Pasci — June 18, 2008 @ 11:19 am

  5. 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 :)

    Thanks.

    Comment by zubfatal — December 15, 2008 @ 3:39 pm

  6. [...] Free the GNU [...]

    Pingback by Syntax highlighting con nano « auraham — January 7, 2009 @ 7:43 am

  7. Thanks for the info.
    I always forgot to un-comment the ‘include’ line from the /etc/nanorc file

    Comment by xjustice — March 14, 2009 @ 8:56 am

  8. Today, your post was again helpful reference, for the n-th time! Thank you!

    Comment by Zen of Linux — March 29, 2009 @ 11:01 am

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

    Comment by Sam — October 9, 2009 @ 5:16 am

    • 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. your done!

      Comment by Pedro Carvalho — October 9, 2009 @ 1:03 pm

  10. [...] I found a great two part [...]

    Pingback by Dubayou[dot]com | Where i like to think. » Nano on the command line. — November 28, 2009 @ 4:54 am

  11. [...] [...]

    Pingback by Programming editor for Linux — December 31, 2010 @ 9:04 pm

  12. helped me out a lot thank you :)

    Comment by Lance — June 8, 2011 @ 2:03 pm

  13. Thanks for the help! It’s great to have syntax highlighting in Nano!

    Comment by Wheat — August 24, 2011 @ 3:24 pm

    • yeah, nano is awesome!

      Comment by Pedro Carvalho — August 25, 2011 @ 6:05 am

  14. [...] לחפש באינטרנט לגבי קבצי תחביר לנאנו, ומסתבר שיש כבר הרבה. ולמעשה בברירת מחדל מותקנים במחשב קבצי תחביר של נאנו [...]

    Pingback by נפלאות הנאנו | הבלוג של נדב ויניק — September 1, 2011 @ 9:03 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

The Shocking Blue Green Theme Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: