TIP_Nano_Context_Highlighting
Contents |
Configuration files
- ~/.nanorc - user specific settings
- /etc/nanorc - global settings
- /usr/share/nano/*.nanorc - Syntax files
If you look at the files in /usr/share/doc/nano-*/*nanorc*, there are already some examples in place you can choose to use as a base. In the next section we'll cover some different language-specific configuration options that have been submitted.
If you wish, you may put your syntaxes in separate files. You can make use of such files in your .nanorc or /etc/nanorc (which can only include "syntax", "color", and "icolor" commands) as follows:
include "/path/to/syntax_file.nanorc"
Default (and example) files are located in /usr/share/nano/. They are included in the /etc/nanorc example file but still commented. (Uncomment to enable) You can also copy /etc/nanorc to your home dir as .nanorc and make customizations there.
Unless otherwise noted, the name of the syntax file (without the ".nanorc" extension) should be the same as the "short description" name inside that file. These names are kept fairly short to make them easier to remember and faster to type using nano's -Y option.
Language specific config examples
PHP
| Code: PHP syntax highlighting |
## PHP syntax highlighting ## syntax "php" "\.php$" "\.php[2345s]$" "\.phtml$" #functions color brightmagenta "([A-Za-z0-9])" #numbers color brightblue "[0-9]" #special color brightwhite "(^|[^A-Za-z0-9])(<\?php|\?>|var|and|or|default|class|extends|true|false|global|function|new|switch|case|break|next|prev|elseif|if|else|foreach|for|as|do|while|exit|die|declare|require_once|require|include_once|include|return|echo|static|array|isset)([^A-Za-z0-9])" #types color brightred "([^A-Za-z0-9])|[^A-Za-z](null|int|string|float|bool|object|resource)[^A-Za-z0-9_]+[^A-Za-z]" #strings color brightyellow ""(\\.|[^\"])*"" color brightyellow "'(\\.|[^\'])*'" #Variables color brightcyan "\$[]\[A-Za-z0-9_'\"]*" #comments color green "//.*" color green "#.*" color green start="/\*" end="\*/" |
Gentoo
ebuild
| Code: ebuilds |
## Here is an example for ebuilds/eclasses
##
syntax "ebuild" "\.e(build|class)$"
## All the standard portage functions
color brightgreen "^src_(unpack|compile|install|test)" "^pkg_(config|nofetch|setup|(pre|post)(inst|rm))"
## Highlight bash related syntax
color green "\<(case|do|done|elif|else|esac|exit|fi|for|function|if|in|local|read|return|select|shift|then|time|until|while)\>"
color green "(\{|\}|\(|\)|\;|\]|\[|`|\\|\$|<|>|!|=|&|\|)"
color green "-(e|d|f|r|g|u|w|x|L)\>"
color green "-(eq|ne|gt|lt|ge|le|s|n|z)\>"
## Highlight variables ... official portage ones in red, all others in bright red
color brightred "\$\{?[a-zA-Z_0-9]+\}?"
color red "\<(ARCH|HOMEPAGE|DESCRIPTION|IUSE|SRC_URI|LICENSE|SLOT|KEYWORDS|FILESDIR|WORKDIR|(P|R)?DEPEND|PROVIDE|DISTDIR|RESTRICT)\>"
color red "\<(S|D|T|PV|PF|P|PN|A)\>" "\<C(XX)?FLAGS\>"
## Highlight portage commands
color magenta "\<use(_(with|enable))?\> [a-z0-9X ]*" "inherit.*"
color brightblue "e(begin|end|conf|install|make|warn|infon?|error|patch)"
color brightblue "\<die\>" "\<use((v|_(with|enable)))?\>" "\<inherit\>" "\<has\>" "\<(has|best)_version\>" "\<unpack\>"
color brightblue "\<(do|new)(ins|s?bin|doc|lib(|\.so|\.a)|man|info|exe)\>"
color brightblue "\<do(python|sed|dir|hard|sym|html|jar|mo)\>" "\<keepdir\>"
color brightblue "prepall(|docs|info|man|strip)" "prep(info|lib|lib\.so|man|strip)"
color brightblue "\<(|doc|ins|exe)into\>" "\<f(owners|perms)\>" "\<(exe|ins|dir)opts\>"
## Highlight common commands used in ebuilds
color blue "\<make\>" "\<(cat|cd|chmod|chown|cp|echo|env|export|grep|let|ln|mkdir|mv|rm|sed|set|tar|touch|unset)\>"
## Highlight comments (doesnt work that well)
color yellow "#.*$"
## Highlight strings (doesnt work that well)
color brightyellow "'(\\.|[^\"])*'" "'(\\.|[^'])*'"
|
/etc/portage/*
| Code: /etc/portage/* |
## Here is an example for Portage control files ## syntax "/etc/portage" "\.(keywords|mask|unmask|use)(/.+)?$" ## Base text: color green "^.+$" ## Use flags: color brightred "[[:space:]]+\+?[a-zA-Z0-9_-]+" color brightblue "[[:space:]]+-[a-zA-Z0-9_-]+" ## Likely version numbers: color magenta "-[[:digit:]].*([[:space:]]|$)" ## Accepted arches: color white "[~-]?\<(alpha|amd64|arm|hppa|ia64|mips|ppc|ppc64|s390|sh|sparc|x86$)" color white "[[:space:]][\*~-]?\*" ## Categories: color cyan "^[[:space:]]*.*/" ## Masking regulators: color brightmagenta "^[[:space:]]*(=|~|<|<=|=<|>|>=|=>)" ## Comments: color yellow "#.*$" |
xorg.conf
| Code: xorg.conf |
## syntax highlighting in xorg.conf ## syntax "xorg" "xorg\.conf$" color brightwhite "(Section|EndSection|Sub[sS]ection|EndSub[sS]ection)" # keywords color yellow "[^A-Za-z0-9](Identifier|Screen|InputDevice|Option|RightOf|LeftOf|Driver|RgbPath|FontPath|ModulePath|Load|VendorName|ModelName|BoardName|BusID|Device|Monitor|DefaultDepth|View[pP]ort|Depth|Virtual|Modes|Mode|DefaultColorDepth|Modeline|\+vsync|\+hsync|HorizSync|VertRefresh)[^A-Za-z0-9]" # numbers color magenta "[0-9]" # strings color green ""(\\.|[^\"])*"" # comments color blue "#.*" |
C
| Code: C |
############################################################################## # # Syntax highlighting for C files # # Author: Josef 'Jupp' Schugt, jupp(a)rubyforge.org # License: GPL 2 or later # # Version: 2004-02-25 # ############################################################################## syntax "c-file" "\.(c|h)$" # Default color white "^.+$" # Trigraphs color brightyellow "\?\?[-=(\\)'<!>]" # Decimal, cotal and hexadecimal numbers color red "\<[-+]?([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 red "\<[-+]?([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([EePp][+-]?[0-9]+)?[fFlL]?" color red "\<[-+]?([0-9]+[EePp][+-]?[0-9]+)[fFlL]?" # Keywords color brightyellow "\<(break|case|continue|default|do|else|for|goto|if)\>" color brightyellow "\<(inline|return|sizeof|switch|typedef|while)\>" # Storage classes color cyan "\<(auto|register|static|extern)\>" # Type qualifiers color cyan "\<(const|restrict|volatile)\>" # Enumerations, structs, and unions color cyan "\<(enum|struct|union)\>" # Type specifiers color cyan "\<(char|double|float|int|long|short|(un)?signed|void)\>" color cyan "\<(_(Bool|Complex|Imaginary)|FILE|va_list|wc(trans|type)_t)\>" color cyan "\<(u?int((_fast|_least)?(8|16|32|64)|max|ptr)|w(char|int))_t|\>" # Preprocessor directives: Conditions color red "^[ \t]*#(ifn?def|else|endif)\>" color red "^[ \t]*#(if|elif)[ \t]*!?[ \t]*(defined)?\>" # Preprocessor directive: Set line number color yellow "^[ \t]*#line\>.*$" color red "^[ \t]*#line\>" # Preprocessor: Issue error message color yellow "^[ \t]*#error\>.*$" color red "^[ \t]*#error\>" # Preprocessor: Pragma (don't ask :-) color yellow "^[ \t]*#pragma\>.*$" color red "^[ \t]*#pragma\>" # Preprocessor: Predefined macros color red "__(LINE|FILE|func|DATE|TIME|STD(C|_HOSTED|_VERSION))__" # Preprocessor directives: Definition color red "^[ \t]*#(define|undef)\>" # Preprocessor directive: File inclusion color yellow "^[ \t]*#include[ \t]*(\"[^"]*\"|<[^>]*>)" color red "^[ \t]*#include\>" # String color yellow "L?\"(\\"|[^"])*\"" color yellow "L?'(\'|[^'])*'" # Escapes color red "\\[0-7][0-7]?[0-7]?|\\x[0-9a-fA-F]+|\\[abfnrtv'"\?\\]" # Comments color magenta start="/\*" end="\*/" color magenta "//.*$" |
ruby
| Code: ruby |
##############################################################################
#
# Ruby syntax highlighting for Nano.
#
# Author: Josef 'Jupp' Schugt, jupp(a)rubyforge.org
# License: GPL 2 or later
#
# Version: 2004-02-27
#
##############################################################################
# Automatically use for '.rb' files
syntax "ruby" ".*\.*rb$"
# General
color white ".+"
# Operators
color brightyellow "::|\*\*|!|~|\*|/|%|\+|-|&|<<|>>|\|\^|>|>=|<|<=|<=>|\|\||!=|=~|!~|&&|\+=|-=|=|\.\.|\.\.\.|\<(not|and|or)\>"
# Keywords
color brightyellow "\<(BEGIN|END|alias|and|begin|break|case|class|def|defined|do|else|elsif|end|ensure|for|if|in|module)\>"
color brightyellow "\<(next|not|or|redo|rescue|retry|return|self|super|then|undef|unless|until|when|while|yield)\>"
# false, nil, true
color magenta "\<(false|nil|true)\>"
# Above must not match 'nil?'
color white "\<nil\?"
# external stuff
color brightgreen "(\<(load|require|include)|%q|%!|%Q|%r|%x)\>"
# Iterators
color brightgreen "\|\w+(,[ \t]*\w+)*\|"
# Constants
color yellow "\<[A-Z]\w*\>"
# Variables starting with '$', '@' or '@@'
color white "(\$|@@?)\w+\>"
# Function names ending in '!' or '?'
color white "\w+(!|\?)"
# Symbols
color yellow "([ \t]|^):(@|@@|\$)?\w+\>"
# Strings
color green "\"(\\.|[^\\\"])*\"|'(\\.|[^\\'])*'"
# Strings
color green "\"(\\.|[^\\\"])*\"|'(\\.|[^\\'])*'"
# Backticks
color green "`(\\.|[^\\\"])*`"
# Regular expressions
color green "/(\\.|[^\\/])*/[imox]*"
# Escapes
color red "\\[0-7][0-7][0-7]|\\x[0-9a-fA-F][0-9a-fA-F]|\\[abefnrs]|(\\c|\\C-|\\M-|\\M-\\C-)."
# Expression substitution
color red "#\{[^}]*\}|#[@$]\w+"
# Simple comments
color cyan "#([^{$@].*)?$"
# Shebang
color brightcyan "^#!.*"
# Multiline comments
color cyan start="^=begin" end="^=end"
|
xml
| Code: xml |
############################################################################## # # Syntax highlighting for XML files # # Author: Josef 'Jupp' Schugt, jupp(a)rubyforge.org # Secondary author: Barry Burns, bburnsatsynsetdotnet # License: GPL 2 or later # # Version: 2007-09-28 # ############################################################################## syntax "ml" ".*\.([jrs]?htm?|xml|xul|rdf|rss|xbl|sgml?)$" color white "^.+$" # Attribute names color green start="<" end=">" # Attribute text color brightgreen ""[^"]+"" # Tag names color brightcyan "<[^> ]+" # Alligators color cyan "<" color cyan ">" # DTDs color brightyellow start="<!DOCTYPE" end="[/]?>" # Comments color white start="<!--" end="-->" # Entities color red "&[^;]*;" # Preprocessing instructions color brightred "<\?.+?>" color red "<\?" color red "\?>" # CDATA color white start="<!\[CDATA\[" end="\]\]>" color brightwhite "<!\[CDATA\[" color brightwhite "\]\]>" |
HTTP
| Code: HTTP |
############################################################################## # # Syntax highlighting for HTTP codes # # Author: Josef 'Jupp' Schugt, jupp(a)rubyforge.org # License: GPL 2 or later # # Version: 2004-02-25 # ############################################################################## syntax "urls" color brightmagenta "^.*$" color cyan "^(1[0-9][0-9]|20[256]|30[45]).*$" color green "^20[03].*$" color brightyellow "^(201|30[0-37]).*$" color brightred "^(204|[45][0-9][0-9]|666).*$" |
Perl
| Code: Perl |
########################################################### # # nano Syntax highlighting for perl files # Author: David Benbennick # # Version: 2003-02-28 # ########################################################### 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|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)?|ord|pack|pipe|pop|printf?|push|q|qq|qx|rand|re(ad(dir|link)?|cv|do|name|quire|set|turn|verse|winddir)|rindex|rmdir|s|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)\>" color magenta "\<(continue|else|elsif|do|for|foreach|if|unless|until|while|eq|ne|lt|gt|le|ge|cmp|x|my|our|sub|use|package|can|isa)\>" color cyan start="address@hidden" end="( |\\W|-)" color yellow "".*"|qq\|.*\|" color white "[sm]/.*/" color white start="(^use| = new)" end=";" color green "#.*" color yellow start="<< 'STOP'" end="STOP" |
CSS
| Code: CSS |
##############################################################################
#
# Syntax highlighting for CSS files
#
# Author: Simon Rupf, simon.rupf(a)int-ag.ch
# License: GPL 2 or later
#
# Version: 2005-02-14
#
# 2008-09-29: Tweaked by kojiro to add '!important' coloring
#
##############################################################################
syntax "css" "\.css$"
color brightcyan "."
color brightyellow start="\{" end="\}"
color brightwhite start=":" end="[;^\{]"
color brightblue ":active|:focus|:hover|:link|:visited|:link|:after|:before|$"
color brightblue start="\/\*" end="\\*/"
color green ";|:|\{|\}"
color brightred "!important"
|
conf
| Code: conf |
# Generic *.conf file syntax highlighting # syntax "conf" "\.(c(onf|nf|fg))$" # string icolor yellow ""(\\.|[^"])*"" # variable name & value icolor brightyellow start="=" end="$" icolor magenta start="(^|[[:space:]])[0-9a-z-]" end="=" # bracket/parenthesis icolor brightred "(^|[[:space:]])((\[|\()[0-9a-z_!@#$%^&*-]+(\]|\)))" # number color green "[[:space:]][0-9.KM]+" # comment color cyan start="(^|[[:space:]])(#|;).*$" end="$" color brightblue "(^|[[:space:]])(#|;)" |
Paludis
nano -Y repo <repository_config-file_path>
| Code: Paludis |
## Here is an example for Paludis control files
##
syntax "bashrc" "bashrc$"
## Base text:
color brightblack "^.+$"
## sh syntax:
color brightwhite "\<(case|do|done|elif|else|esac|exit|fi|for|function|if|in|local|read|return|select|shift|then|time|until|while)\>"
icolor magenta "(.+\)|\[.+\])"
color brightwhite "(\{|\}|\(|\)|\;|\]|\[|`|\\|\$|<|>|!|==|&|\|)"
color brightwhite "-[Ldefgruwx]\>"
color brightwhite "-(eq|ne|gt|lt|ge|le|s|n|z)\>"
color brightblue "\<(cat|cd|chmod|chown|cp|echo|env|export|grep|install|let|ln|make|mkdir|mv|rm|sed|set|tar|touch|umask|unset)\>"
icolor brightred "\$\{?[0-9A-Z_!@#$*?-]+\}?"
color ,green "[[:space:]]+$"
color green "\".*\""
color brightwhite "case[[:space:]]\".+\""
color brightgreen "\$\{.+\}"
## Package name:
color brightmagenta "\$\{PN\}"
## Keywords:
color brightwhite "(CHOST|CFLAGS|CXXFLAGS|MAKEOPTS)="
color white "(SKIP_FUNCTIONS|PATH|CCACHE_SIZE|CCACHE_DIR|PALUDIS_USE_SAFE_RESUME)="
## Comments:
color brightred "#.*$"
color yellow "^#.*$"
color brightyellow "^##[[:space:]].*$"
syntax "license-use" "(licenses|use)\.conf$"
## Base text:
color brightblack "^.+$"
## Package name:
color brightblue "/.*[[:space:]]"
## Categories:
color cyan "^.*/"
## Version number:
color white "-[[:digit:]]+(\.|[[:digit:]]|-.)*([[:space:]]|::)"
## Repository name:
color magenta "::.*[[:space:]]"
## licenses and use:
color green "[[:space:]][^[:space:]]*"
color red "[[:space:]]-[^[:space:]]*"
## Masking regulators:
color brightred "^(<|<=|=|>=|>)*"
color brightwhite "^(<|<=|=|>=|>)"
## Additional variables:
color brightgreen "(ALSA_CARDS|INPUT_DEVICES|LANGUAGE|LINGUAS|VIDEO_CARDS|PALUDIS_HOOKS):?"
## Mark lines with spaces at end of it:
color brightred ".*[[:space:]]$"
## Comments:
color brightred "#.*$"
color yellow "^#.*$"
color brightyellow "^##[[:space:]].*$"
syntax "keywords" "keywords\.conf$"
## Base text:
color brightblack "^.+$"
## Package name:
color brightblue "/.*[[:space:]]"
## Categories:
color cyan "^.*/"
## Version number:
color white "-[[:digit:]]+(\.|[[:digit:]]|-.)*([[:space:]]|::)"
## Repository name:
color magenta "::.*[[:space:]]"
## Accepted arches:
color green "[[:space:]][~]?(alpha|amd64|arm|hppa|ia64|mips|ppc|ppc64|s390|sh|sparc|x86|x86-fbsd|\*)"
color red "-\*"
## Masking regulators:
color brightred "^(<|<=|=|>=|>)*"
color brightwhite "^(<|<=|=|>=|>)"
## Mark lines with spaces at end of it:
color brightred ".*[[:space:]]$"
## Comments:
color brightred "#.*$"
color yellow "^#.*$"
color brightyellow "^##[[:space:]].*$"
syntax "mask-unmask" "package_(mask|unmask)\.conf$"
## Base text:
color brightblack "^.+$"
## Package name:
color brightblue "/.*"
## Categories:
color cyan "^.*/"
## Version number:
color white "-[[:digit:]]+(\.|[[:digit:]]|-.)*($|::)"
## Repository name:
color magenta "::.*$"
## Masking regulators:
color brightred "^(<|<=|=|>=|>)*"
color brightwhite "^(<|<=|=|>=|>)"
## Mark lines with spaces at end of it:
color brightred ".*[[:space:]]$"
## Comments:
color brightred "#.*$"
color yellow "^#.*$"
color brightyellow "^##[[:space:]].*$"
syntax "mirrors" "mirrors\.conf$"
## Base text:
color red "^.+$"
## Serwer name:
color brightwhite "^.*[[:space:]]"
## Adress
color brightblue "[[:space:]](ftp://|http://).*$"
## Mark lines with spaces at end of it:
color brightred ".*[[:space:]]$"
## Comments:
color brightred "#.*$"
color yellow "^#.*$"
color brightyellow "^##[[:space:]].*$"
syntax "repositories" "repo"
## Base text:
color brightblack "^.+$"
## Parameters:
color magenta "=[[:space:]].+$"
color brightwhite "^.*[[:space:]]=[[:space:]]"
## Path:
color green "/.+"
color brightgreen "\$\{.*\}"
## Adress:
color brightblue "(svn\+https|svn\+http|http|rsync)://.*$"
## Mark lines with spaces at end of it:
color brightred ".*[[:space:]]$"
## Comments:
color brightred "#.*$"
color yellow "^#.*$"
color brightyellow "^##[[:space:]].*$"
|
ECMAScript/JavaScript
| Code: JavaScript/ECMAScript |
# ECMAScript/JavaScript/JScript/ActionScript/LiveScript (ugh!) Syntax Highlighting
# by Barry Burns <bburns at synset dot net>
# License: GPL 2 or later
syntax "ecmascript" "\.js$"
color white "^.+$"
# Identifiers
color brightcyan "\b[a-zA-Z\$_][a-zA-Z0-9\$_]*\b"
# Braces, brackets and parentheses
color brightmagenta "\[|\]|\(|\)|\{|\}"
# Integers, floats
color brightblue "\b[0-9]+(.[0-9]+)?\b"
# Reserved words
color brightyellow "\b(break|case|catch|continue|default|delete|do|else|finally|for|function|if|in|instanceof|new|return|switch|this|throw|try|typeof|var|void|while|with)\b"
# Operations
color brightgreen "\||~|!|\.|\*|\+|-|=|<|>|/"
# Strings
color blue ""[^"]*""
color blue "'[^']*'"
# Comments
color brightwhite "//[^\n]*"
color brightwhite start="/\*" end="\*/"
|
HTML
| Code: HTML |
# ECMAScript/JavaScript/JScript/ActionScript/LiveScript (ugh!) Syntax Highlighting # by -- # License: GPL 2 (not later) syntax "HTML" "\.html$" # list of tags color brightcyan "<[\/]?(html|head|title|metal|link|meta|table|tr|td|h[1-6])[>]?" # list of attributes color cyan "(alt|src|type|onclick|name|content|id|class|style)" # text in quotes color brightwhite ""(\\.|[^\"])*"" # comments color yellow start="<!--" end="-->" # html entities color red "&[^; ]*;" |
See also
- Syntax Highlighting in Nano
- Nano Syntax Highlighting
- Nano syntax highlighting for Bash
- Nano Syntax Highlighting
Created by NickStallman.net, Luxury Homes Australia
Real estate agents should be using interactive floor plans and real estate agent tools.
