Nano Nano

bnrubin | Ubuntu, howto, linux | Monday, July 28th, 2008

I use nano as my primary CLI editor.  It may not have as many features as vi(m) or Emacs (in no particular order), it is fast and easy for me.

One of the features that many people do not realize that nano supports is syntax highlighting.  This can quickly and easily be enabled by following these directions:

nano will automatically read in ~/.nanorc if it exists. Since you probably don’t have that file there already, go ahead and copy the sample file out of /etc:

 [pici@romulus:~]$ cp /etc/nanorc ~/.nanorc

Highlighting for each language needs to be turned on explicitly in your new .nanorc file. In Intrepid, the lines specifying each language begin around line 217, which is probably around the same area in other releases. If not, this is what you’re looking for something similar to this:

some default languages supported by nanorc:
## Nanorc files
include "/usr/share/nano/nanorc.nanorc"
 
## C/C++
include "/usr/share/nano/c.nanorc"
 
## HTML
include "/usr/share/nano/html.nanorc"
 
## TeX
include "/usr/share/nano/tex.nanorc"
 
## Quoted emails (under e.g. mutt)
# include "/usr/share/nano/mutt.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"
 
## Ruby
include "/usr/share/nano/ruby.nanorc"
 
## Java
include "/usr/share/nano/java.nanorc"
 
## Assembler
include "/usr/share/nano/asm.nanorc"
 
## Bourne shell scripts
include "/usr/share/nano/sh.nanorc"
 
## POV-Ray
#include "/usr/share/nano/pov.nanorc"

Go ahead and remove the hash from each include statement for the languages you wish to enable, and you’re all done.

Some other options that I find helpful to have in my .nanorc are as follows:

Other options:
## Setup tabs
set autoindent
set tabstospaces
set tabsize "4"
## Don't wrap text at all.
set nowrap

Screenshot coming soon.

Powered by WordPress | Theme by Roy Tanck