2

Has anyone got (or can point in the direction of) a nanorc file that contains syntax highlighting for C# and/or ASP.Net?

  • You probably won't find one for ASP seeing as how it's typically a Windows language and up until recently wasn't able to function on Linux Machine. – Marco Ceppi Aug 13 '10 at 13:47
  • Duplicated unix.stackexchange.com/questions/454/… and – Marco Ceppi Aug 13 '10 at 20:38
  • Marco - duplicated because not all Ubuntu stackexchange people have access to the Unix one cos its in private beta. Also, some people on the Unix one may use distros other than Ubuntu. – Rob Cowell Aug 14 '10 at 9:34
  • @Marco Not a duplicate for the same reason the @Rob mentioned. – jrg Jun 5 '11 at 18:44
2

I don't know of an existing highlight for C# in Nano but you could write your own. The syntax for syntax highlighting is pretty simple. Here's the one for Java (which will be very similar to a C# syntax - mainly just different keywords):

## Here is an example for Java.
##
syntax "java" "\.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|instanceof|interface|native|package|private|protected|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 ,green "[[:space:]]+$"

That's sitting in /usr/share/nano/java.nanorc. If you write your own you'll need to link to it from /etc/nanorc. There may be a user-local version of both too but I don't know it.

Edit: for ASP.NET you could just clone the HTML one and alter the syntax slightly to handle ASP.NET tags. It won't be perfect (it won't handle <script runat="server">...</script> contents for example) but it should be better than a poke in the eye with a sharp stick.

  • Ok, I'll make a start, was looking for a pre-made one cos I'm lazy ;-) – Rob Cowell Aug 14 '10 at 9:35
2

Replicating my answer.

Using the Java example from http://wiki.linuxhelp.net/index.php/Nano_Syntax_Highlighting, you can try to add something like the following into your ~/.nanorc:

syntax "C# source" "\.cs$"
color green "\<(bool|byte|sbyte|char|decimal|double|float|int|uint|long|ulong|new|object|short|ushort|string|base|this|void)\>"
color red "\<(as|break|case|catch|checked|continue|default|do|else|finally|fixed|for|foreach|goto|if|is|lock|return|switch|throw|try|unchecked|while)\>"
color cyan "\<(abstract|class|const|delegate|enum|event|explicit|extern|implicit|in|internal|interface|namespace|operator|out|override|params|private|protected|public|readonly|ref|sealed|sizeof|static|struct|typeof|using|virtual|volatile)\>"
color red ""[^\"]*""
color yellow "\<(true|false|null)\>"
color blue "//.*"
color blue start="/\*" end="\*/"
color brightblue start="/\*\*" end="\*/"
color brightgreen,green " +$"

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.