Click to See Complete Forum and Search --> : Colorizing Nano


Syngin
01-09-2008, 09:24 AM
I came across this and thought it might be really helpful to some people. If you use nano (pico clone) as your text editor, the following link will show you how to colorize the code.

Very handy.

http://wiki.linuxhelp.net/index.php/Nano_Syntax_Highlighting

Syngin
01-09-2008, 09:55 AM
Basically, create a file called .nanorc in the root of your home directory and paste something like the following into it and Presto!, colorized code (NOTE: each line should start with either a #, syntax or color (the forum is doing some annoying text wrapping):

#PHP
syntax "php" "\.php[2345s~]?$"
color brightblue "(.*)\("
color white "\$[a-zA-Z_0-9$]*|[=!<>]"
color green "(var|class|function|echo|case|break|default|exit|s witch|if|else|elseif|@|while)\s"
color green "[.,{}();]"
color red "('.*')|(\".*\")"
color brightyellow "(#.*|//.*)$"
color brightyellow start="/\*" end="\*/"
color brightred "(<\?(php)?|\?>)"
color white start="\?>" end="<\?(php)?"

#HTML
syntax "HTML" "\.html$"
color blue start="<" end=">"
color white "&[^; ]*;"

#Perl
syntax "perl" "\.p[lm]$"
color red "\<(accept|alarm|atan2|bin(d|mode)|c(aller|h(dir|mod| op|own|root)|lose(dir)?|onnect|os|rypt)|d(bm(close |open)|efined|elete|ie|o|ump)|e(ach|of|val|x(ec|is ts|it|p))|f(cntl|ileno|lock|ork)|get(c|login|peern ame|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|ke ys|kill|last|length|link|listen|local(time)?|log|l stat|m|mkdir|msg(ctl|get|snd|rcv)|next|oct|open(di r)?|ord|pack|pipe|pop|printf?|push|q|qq|qx|rand|re (ad(dir|link)?|cv|do|name|quire|set|turn|verse|win ddir)|rindex|rmdir|s|scalar|seek|seekdir|se(lect|m ctl|mget|mop|nd|tpgrp|tpriority|tsockopt)|shift|sh m(ctl|get|read|write)|shutdown|sin|sleep|socket(pa ir)?|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) \>"
color blue "\<(continue|else|elsif|do|for|foreach|if|unless|unti l|while|eq|ne|lt|gt|le|ge|cmp|x|my|our|sub|use|pac kage|can|isa)\>"
color white start="[$@%]" end="( |\\W|-)"
color yellow ""[^"]*"|qq\|.*\|"
color red "'[^']*'"
color white "[sm]/.*/"
color white start="(^use| = new)" end=";"
color green "#.*"
color yellow start="<< 'STOP'" end="STOP"

#Javascript
syntax "JavaScript" "\.(js)$"
# Default
color white "^.+$"
# Decimal, cotal and hexadecimal numbers
color yellow "\<[-+]?([1-9][0-9]*|0[0-7]*|0x[0-9a-fA-F]+)([uU][lL]?|[lL][uU]?)?\>"
# Floating point number with at least one digit before decimal point
color yellow "\<[-+]?([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([EePp][+-]?[0-9]+)?[fFlL]?"
color yellow "\<[-+]?([0-9]+[EePp][+-]?[0-9]+)[fFlL]?"
# Keywords
color green "\<(break|case|catch|continue|default|delete|do|else| finally)\>"
color green "\<(for|function|if|in|instanceof|new|null|return|swi tch)\>"
color green "\<(switch|this|throw|try|typeof|undefined|var|void|w hile|with)\>"
# Type specifiers
color red "\<(Array|Boolean|Date|Enumerator|Error|Function|Math )\>"
color red "\<(Number|Object|RegExp|String)\>"
color red "\<(true|false)\>"
# String
color brightyellow "L?\"(\\"|[^"])*\""
color brightyellow "L?'(\'|[^'])*'"
# Escapes
color red "\\[0-7][0-7]?[0-7]?|\\x[0-9a-fA-F]+|\\[bfnrt'"\?\\]"
# Comments
color magenta start="/\*" end="\*/"
color magenta "//.*$"

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

JohnT
01-09-2008, 11:06 AM
Will be very useful. Something that I can use.;)

loopback48
01-10-2008, 05:12 AM
Can I just copy and past your example? And just what correction will I have to do, if any to it? Or can you correct it?

Also, can you give an example of the end result? Like to see it.

Thanks.

mrrangerman43
01-10-2008, 06:41 AM
Thanks I've been working with C trying to learn it, so I started using emacs because it colors code but nano is my editor of choice.

spx2
01-15-2008, 03:33 PM
No editor wars please ... but ..
why not use vim ?
it has
It's as easy as :sy on
and you have color in Vim.
And you can also use it as a full blown IDE with Vim Project wich you can
find here http://code.google.com/p/perlhobby/ with instructions how to install
it and a screenshot to see if it fits your needs.

JohnT
01-15-2008, 05:30 PM
Not as much an editor issue, but more of a "what's included with my distro" issue. Nano/Pico are the two most common that are available with a new setup.

spx2
01-15-2008, 05:32 PM
oh yes...thats true...then again I consider vim as a default editor,from my point of view at least...

mrrangerman43
01-16-2008, 06:46 AM
spx2

No editor wars please ... but ..
why not use vim ?
it has
It's as easy as


:sy on

and you have color in Vim.
And you can also use it as a full blown IDE with Vim Project wich you can
find here http://code.google.com/p/perlhobby/ with instructions how to install
it and a screenshot to see if it fits your needs.


Nice, in Debian to get vim with this feature I had to install vim-full

apt-get install vim-full

Thanks