2

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

5
  • 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. Aug 13, 2010 at 13:47
  • Duplicated unix.stackexchange.com/questions/454/… and Aug 13, 2010 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, 2010 at 9:34
  • @Marco Not a duplicate for the same reason the @Rob mentioned.
    – jrg
    Jun 5, 2011 at 18:44
  • This one is great github.com/scopatz/nanorc
    – Matze
    Jul 12, 2021 at 18:21

3 Answers 3

3

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 " +$"
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.

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

This works for me:

syntax "cs" "\.cs$"
magic "Cs "
comment "//"

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|size$
color red ""[^\"]*""
color yellow "\<(true|false|null)\>"
color blue "//.*"
color blue start="/\*" end="\*/"
color brightblue start="/\*\*" end="\*/"
color brightgreen,green " +$"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .