Notices


Reply
Thread Tools
Posts: 86 | Thanked: 24 times | Joined on Jan 2008
#1
I use nano a lot, and find it much easier to use with color output. This is my nanorc file, which you can save as '/home/user/.nanorc' and '/root/.nanorc' or you can save it as '/etc/nanorc' and symlink those files to it.

It has color highlighting for several programming languages, but is prolly most useful when editing conf and shell script files.

Download: http://burmashave.net/media/files/nanorc.gz

Code:
## Initialization file for GNU nano
## Please note that you must have configured nano with --enable-nanorc
## for this file to be read!  Also note that characters especially
## interpreted by the shell should not be escaped here.
##
## To make sure a value is not enabled, use "unset <option>"
##
## For the options that take parameters, the default value is given.
## Other options are unset by default.

## Use auto-indentation
set autoindent

## Backup files to filename~
# set backup

## The directory to put the backup files in.
# set backupdir ""

## Constantly display the cursor position in the status bar.
set const

## Use cut to end of line with ^K by default
# set cut

## Set the line length for wrapping text and justifying paragraphs.
## If fill is negative, the line length will be the screen width less
## this number.
##
# set fill -8
 
## Enable ~/.nano_history for saving and reading search/replace strings.
# set historylog

## Allow multiple file buffers (using ^R inserts into separate buffer).
## You must have configured with --enable-multibuffer or --enable-extra
## for this to work.
##
## set multibuffer

## Don't convert files from DOS/Mac format
# set noconvert

## Don't follow symlinks when writing files
# set nofollow

## Don't display the help lists at the bottom of the screen
set nohelp

## Don't wrap text at all
set nowrap

## Set operating directory.  nano will not read or write files outside
## this directory and its subdirectories.  Also, the current directory
## is changed to here, so files are inserted from this dir.  A blank
## string means the operating directory feature is turned off.
##
# set operatingdir ""

## Preserve the XON and XOFF keys (^Q and ^S)
# set preserve

## The email-quote string, used to justify email-quoted paragraphs.
## This is an extended regular expression if your system supports them,
## otherwise a literal string.  Default:
# set quotestr "^([ ]*[\|>:}#])+"
## if you have regexps, otherwise:
# set quotestr "> "
## You can get old nano quoted-justify behavior via:
# set quotestr "(> )+"

## Fix Backspace/Delete confusion problem
# set rebinddelete

## Do extended regular expression searches by default 
set regexp

## Use smooth scrolling as the default
set smooth

## Use this spelling checker instead of the internal one.  This option
## does not properly have a default value.
##
# set speller "aspell -c"

## Allow nano to be suspended with ^Z
# set suspend

## Use this tab size instead of the default; it must be greater than 0
set tabsize 8

## Use this tab char instead of the default space; it can either be the
## ascii value of the character you wish to see (refer to ascii(7)) or
## it can be a single character.  187 seems to be a 'good' value.
# set tabconvert 32
## Same as tabconverting above, but applied to spaces.
## it can be a single character.  183 seems to be a 'good' value.
# set spaceconvert 32
## Finally, you can toggle whitespace converting with this
# set wsconvert

## Save automatically on exit, don't prompt
# set tempfile

## Disallow file modification, why would you want this in an rc file? ;)
# set view

##
## Color setup
## Format:
## syntax "short description" ["filename regex" ...]
## color foreground,background "regex" ["regex"...]
##
## Legal colors: white, black, red, blue, green, yellow, magenta, cyan.
## You may use the prefix "bright" to mean a stronger color highlight.
##
## To use multi-line regexes use the start="regex" end="regex" format.
##

## Shell Scripts
##
syntax "shellscript" "\.sh$" "\.?profile$" "\.?bashrc$" "\.?cshrc$" "^rc\..*" 

# keywords
  color brightblue "\<(case|do|done|elif|else|esac|exit|fi|for|function|if|in|local|read|return|select|shift|then|time|until|while)\>"
# operators
  color white "(\{|\}|\(|\)|\;|\]|\[|`|\\|<|>|!|=|&|\|)"   
# quotes (double/single/backticks)
  color brightcyan "`(\\.|[^`])*`"
  color yellow ""(\\.|[^\"])*""
  color yellow "'(\\.|[^'])*'" 
# variables (define/defined/bracketed/unhighlight '=')
#  color cyan "[a-zA-Z_0-9#?*@$<\-_!]+="
  color cyan "\$[a-zA-Z_0-9?*@$<\-_!]+"
  color cyan "\$\{[^}]*\}"
  color cyan "\$#"
#  color white "="  
# comments 
  # hashes at line beg or after whitespace
  color green "((^#)|(\s#)).*$"   
  # magic number
  color brightgreen "#!.*$"

## Basic Conf Scripts
##
# just color comments
syntax "confile" "\.co?nf" "\.config$" "\.?logout$" "\.?inittab$" "pf.conf" "^hostname\." "fstab" "\.?nanorc" 
color green "#.*$"

## Patch files
##
syntax "patch" "\.(patch|diff)$"
color brightgreen "^\+.*"
color green "^\+\+\+.*"
color brightblue "^ .*"
color brightred "^-.*"
color red "^---.*"
color brightcyan "^ <at>  <at> .*"
color magenta "^diff.*"

## Perl
##
syntax "perl" "\.p[lm]$"
# subroutine execution
color brightgreen "(.*\(.*\);)"
# operators and some symbol characters
  color brightred "(\&\&|\|\||\=\=|\,|\;| \/ | \* | \= |\$|\@|\%|\=\~)"
# builtin references
  color brightblue "\<(accept|alarm|atan2|bin(d|mode)|c(aller|h(dir|mod|omp|op|own|root)|lose(dir)?|onnect|os|rypt)|d(bm(close|open)|efined|elete|ie|o|ump)|e(ach|of|val|x(ec|ists|it|p))|f(cntl|ileno|lock|ork)|get(c|login|peername|pgrp|ppid|priority|pwnam|(host|net|proto|serv)byname|pwuid|grgid|(host|net)byaddr|protobynumber|servbyport)|([gs]et|end)(pw|gr|host|net|proto|serv)ent|getsock(name|opt)|gmtime|goto|grep|hex|index|int|ioctl|join|keys|kill|last|length|link|listen|local(time)?|log|lstat|m|mkdir|msg(ctl|get|snd|rcv)|next|oct|open(dir|2|3)?|ord|pack|pipe|pop|printf?|push|q|qq|qx|rand|re(ad(dir|link)?|cv|do|name|quire|set|turn|verse|winddir)|rindex|rmdir|scalar|seek|seekdir|se(lect|mctl|mget|mop|nd|tpgrp|tpriority|tsockopt)|shift|shm(ctl|get|read|write)|shutdown|sin|sleep|socket(pair)?|sort|spli(ce|t)|sprintf|sqrt|srand|stat|study|substr|symlink|sys(call|read|tem|write)|tell(dir)?|time|tr|y|truncate|umask|un(def|link|pack|shift)|utime|values|vec|wait(pid)?|wantarray|warn|write)\>"
# logical references
  color brightblue "\<(and|or|continue|else|elsif|do|for|foreach|if|unless|until|while|eq|ne|lt|gt|le|ge|cmp|x|my|sub|use|package|can|isa)\>"
# regexes (part 1)
  color brightcyan "[sm]/.*/"
  color brightcyan "[sm]/.*/.*/."
# try to do new/use.. doesnt work perfectly
  color white start="(^use| = new)" end=";"
  color white start="(^use| = new)" end=";"
# variables
  #color cyan start="[$@%]" end="( |\\W|-|\n)"
  color cyan "[$@%][a-zA-Z_0-9#?*@$<\-_!]+"
# try and fix the ;'s at the end of every statement
  color brightred "\;$|;.*#|;.*}"
# block reading
  color red "<.*>"
# try and tidy up ->'s, parenthesis's, curly braces and square braces
  color yellow "(\(|\)|->|\{|\}|\[|\])"
# regexes and quotations
  color brightcyan "/.*/|/.*/\w+"
  color brightyellow "'.*'|".*"|qq\|.*\|"
# comments - can get confused if inside quotations
  color green "#.*"
# block quotes/input
  color white start="<<STOP" end="STOP"
  color white start="<<EOF" end="EOF"
  color white start="<<START" end="START"

## HTML
##
syntax "HTML" "\.html$" "\.htm$"
# legitimate tags
  color brightcyan start="</?(!DOCTYPE|A|ABBR|ACRONYM|ADDRESS|APPLET|AREA|B|BASE|BASEFONT|BDO|BGSOUND|BIG|BLINK|BLOCKQUOTE|BODY|BR|BUTTON|CAPTION|CENTER|CITE|CODE|COL|COLGROUP|DD|DEL|DFN|DIR|DIV|DL|DT|EM|EMBED|FIELDSET|FONT|FORM|FRAME|FRAMESET|H1|H2|H3|H4|H5|H6|HEAD|HR|HTML|I|IFRAME|ILAYER|IMG|INPUT|INS|ISINDEX|KBD|KEYGEN|LABEL|LAYER|LEGEND|LI|LINK|LISTING|MAP|MENU|META|MULTICOL|NOBR|NOEMBED|NOFRAMES|NOLAYER|NOSCRIPT|OBJECT|OL|OPTGROUP|OPTION|P|PARAM|PLAINTEXT|PRE|Q|S|SAMP|SCRIPT|SELECT|SERVER|SMALL|SOUND|SPACER|SPAN|STRIKE|STRONG|STYLE|SUB|SUP|TBODY|TEXTAREA|TITLE|TT|U|UL|VAR|WBR|XMPTABLE|TD|TFOOT|TH|THEAD|T)( |>)" end=">"
  color brightcyan start="</?(!doctype|a|abbr|acronym|address|applet|area|b|base|basefont|bdo|bgsound|big|blink|blockquote|body|br|button|caption|center|cite|code|col|colgroup|dd|del|dfn|dir|div|dl|dt|em|embed|fieldset|font|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|hr|html|i|iframe|ilayer|img|input|ins|isindex|kbd|keygen|label|layer|legend|li|link|listing|map|menu|meta|multicol|nobr|noembed|noframes|nolayer|noscript|object|ol|optgroup|option|p|param|plaintext|pre|q|s|samp|script|select|server|small|sound|spacer|span|strike|strong|style|sub|sup|tbody|textarea|title|tt|u|ul|var|wbr|xmp|table|td|tfoot|th|thead|tr)( |>)" end=">"
# table tags
  color brightred "</?(TABLE|TD|TFOOT|TH|THEAD|TR)"
  color brightred "</?(table|td|tfoot|th|thead|tr)"
# attributes
  color brightblue " (ACCESSKEY|ACTION|ALIGN|ALINK|ALT|BACKGROUND|BALANCE|BEHAVIOR|BGCOLOR|BGPROPERTIES|BORDER|BORDERCOLOR|BORDERCOLORDARK|BORDERCOLORLIGHT|BOTTOMMARGIN|CELLPADDING|CELLSPACING|CHECKED|CLASS|CLASSID|CLEAR|CODE|CODEBASE|CODETYPE|COLOR|COLS|COLSPAN|COMPACT|CONTENT|CONTROLS|COORDS|DATA|DATAFLD|DATAFORMATAS|DATASRC|DIRECTION|DISABLED|DYNSRC|ENCTYPE|EVENT|FACE|FOR|FRAME|FRAMEBORDER|FRAMESPACING|HEIGHT|HIDDEN|HREF|HSPACE|HTTP-EQUIV|ID|ISMAP|LANG|LANGUAGE|LEFTMARGIN|LINK|LOOP|LOWSRC|MARGINHEIGHT|MARGINWIDTH|MAXLENGTH|MAYSCRIPT|METHOD|METHODS|MULTIPLE|NAME|NOHREF|NORESIZE|NOSHADE|NOWRAP|PALETTE|PLUGINSPAGE|PUBLIC|READONLY|REL|REV|RIGHTMARGIN|ROWS|ROWSPAN|RULES|SCROLL|SCROLLAMOUNT|SCROLLDELAY|SCROLLING|SELECTED|SHAPE|SIZE|SPAN|SRC|START|STYLE|TABINDEX|TARGET|TEXT|TITLE|TOPMARGIN|TRUESPEED|TYPE|URL|URN|USEMAP|VALIGN|VALUE|VLINK|VOLUME|VRML|VSPACE|WIDTH|WRAP)"
  color brightblue " (accesskey|action|align|alink|alt|background|balance|behavior|bgcolor|bgproperties|border|bordercolor|bordercolordark|bordercolorlight|bottommargin|cellpadding|cellspacing|checked|class|classid|clear|code|codebase|codetype|color|cols|colspan|compact|content|controls|coords|data|datafld|dataformatas|datasrc|direction|disabled|dynsrc|enctype|event|face|for|frame|frameborder|framespacing|height|hidden|href|hspace|http-equiv|id|ismap|lang|language|leftmargin|link|loop|lowsrc|marginheight|marginwidth|maxlength|mayscript|method|methods|multiple|name|nohref|noresize|noshade|nowrap|palette|pluginspage|public|readonly|rel|rev|rightmargin|rows|rowspan|rules|scroll|scrollamount|scrolldelay|scrolling|selected|shape|size|span|src|start|style|tabindex|target|text|title|topmargin|truespeed|type|url|urn|usemap|valign|value|vlink|volume|vrml|vspace|width|wrap)"  
# quotes within tags
  color yellow ""(\\.|[^\"])*""
  color yellow "'(\\.|[^'])*'" 
# everything outside of tags
  color white start=">" end="<"
# amp escapes
  color brightmagenta start="&" end=";"
# tag delimiters
  color brightcyan "<|>"
# comments
  color green start="<!--" end="-->"  

## XML
##
syntax "XML" "\.xml$" "\.fdi$"
# legitimate tags
  color brightcyan start="<" end=">"
# quotes within tags
  color yellow ""(\\.|[^\"])*""
  color yellow "'(\\.|[^'])*'"
# everything outside of tags
  color brightwhite start=">" end="<"
# amp escapes
  color brightmagenta start="&" end=";"
# tag delimiters
  color brightcyan "<|>"
# comments
  color green start="<!--" end="-->"

## Java
##
syntax "Java source" "\.java$"
color cyan "\<(boolean|byte|char|double|float|int|long|new|short|this|transient|void)\>"
color brightblue "\<(break|case|catch|continue|default|do|else|finally|for|if|return|switch|throw|try|while)\>"
color brightcyan "\<(abstract|class|extends|final|implements|import|instanceof|interface|native|package|private|protected|public|static|strictfp|super|synchronized|throws|volatile)\>"
color red ""[^\"]*""
color magenta "\<(true|false|null)\>"
color green "//.*"
color green start="/\*" end="\*/"
color brightblue start="/\*\*" end="\*/"
color brightgreen,green " +$"

## Python
##
syntax "Python" "\.py$"
# operators
  # color red "\{|\[|\(|\)|\]|\}|\-|\+|\*|/|<|>|\!|~|%|^|&|\|=|\\"
# built-in objects, attributes, and functions
  color cyan "\<(None|self|__builtin__|__dict__|__methods__|__members__|__class__|__bases__|__import__|__name__|__doc__|__self__|__debug__|abs|append|apply|buffer|callable|chr|clear|close|closed|cmp|coerce|compile|complex|conjugate|copy|count|delattr|dir|divmod|eval|execfile|extend|fileno|filter|float|flush|get|getattr|globals|has_key|hasattr|hash|hex|id|index|input|insert|int|intern|isatty|isinstance|issubclass|items|keys|len|list|locals|long|map|max|min|mode|name|oct|open|ord|pop|pow|range|raw_input|read|readline|readlines|reduce|reload|remove|repr|reverse|round|seek|setattr|slice|softspace|sort|str|tell|truncate|tuple|type|unichr|unicode|update|values|vars|write|writelines|xrange|zip)\>"
# special method names
  color cyan "\<(__abs__|__add__|__and__|__call__|__cmp__|__coerce__|__complex__|__concat__|__contains__|__del__|__delattr__|__delitem__|__delslice__|__div__|__divmod__|__float__|__getattr__|__getitem__|__getslice__|__hash__|__hex__|__init__|__int__|__inv__|__invert__|__len__|__long__|__lshift__|__mod__|__mul__|__neg__|__nonzero__|__oct__|__or__|__pos__|__pow__|__radd__|__rand__|__rcmp__|__rdiv__|__rdivmod__|__repeat__|__repr__|__rlshift__|__rmod__|__rmul__|__ror__|__rpow__|__rrshift__|__rshift__|__rsub__|__rxor__|__setattr__|__setitem__|__setslice__|__str__|__sub__|__xor__)\>"
# exception classes
  # color cyan "\<(Exception|StandardError|ArithmeticError|LookupError|EnvironmentError|AssertionError|AttributeError|EOFError|FloatingPointError|IOError|ImportError|IndexError|KeyError|KeyboardInterrupt|MemoryError|NameError|NotImplementedError|OSError|OverflowError|RuntimeError|SyntaxError|SystemError|SystemExit|TypeError|UnboundLocalError|UnicodeError|ValueError|WindowsError|ZeroDivisionError)\>"
# types
  color brightcyan "\<(NoneType|TypeType|IntType|LongType|FloatType|ComplexType|StringType|UnicodeType|BufferType|TupleType|ListType|DictType|FunctionType|LambdaType|CodeType|ClassType|UnboundMethodType|InstanceType|MethodType|BuiltinFunctionType|BuiltinMethodType|ModuleType|FileType|XRangeType|TracebackType|FrameType|SliceType|EllipsisType)\>"
# definitions
  color brightcyan "def [a-zA-Z_0-9]+" 
# keywords
  color brightblue "\<(and|assert|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|map|not|or|pass|print|raise|return|try|while)\>" 
# quoted strings
  color yellow ""(\\.|[^\"])*""
  color yellow "'(\\.|[^'])*'" 
# comments
# block commenting of """ doesn't work - color quotes only instead
  color green """""
  color green "'''"
  color green "#.*$"
 

The Following User Says Thank You to burmashave For This Useful Post:
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 21:44.