Learning Linux: syntax highlighting in nano

January 21st, 2009
by Kurt

In case you are not familiar with it, nano is a basic text editor that comes with many Linux distributions.  It has a lower learning curve than vi or emacs, but also fewer features.

However, you can spruce nano up a bit by enabling features in its configuration file, “.nanorc” under your home directory.  Specifically, you can provide regular expression based syntax highlighting rules.

For your entertainment, I present meta-syntax highlighting rules for nano. These syntax rules, when put into your .nanrc file, will cause nano to syntax highlight the .nanorc file.

syntax "nanorc" "\.nanorc$"
color brightred "(color|syntax|set|start=|end=)"
color green "(red|brightred|green|brightgreen|blue|brightblue|cyan|brightcyan|white|brightwhite|yellow|brightyellow)"
color brightcyan "#+(.*)"
color brightyellow "\"(([^']|\\\")*|\[(^]]|\\\]|\^\])*\])*\""
color brightblue "[^\\\^]\[(\^\])?([^]]|[\\]{1,3,5,7,9}\])*\]"
color brightgreen "\(" "\)" "[|]"
color brightred "\^"
color red "\\."

Here is what this looks like when applied (to itself):

Posted in Uncategorized | Comments (0)

No comments yet

Leave a Reply