Friday, November 30, 2007

Notepad++ Tip: Syntax Highlighting for ASP.NET Files

Notepad++ has a spot in my toolbox mostly because I like it as a lightweight viewer/editor for one-off situations where I really don't feel like loading up Visual Studio just to take a quick peek at a file.

When I first started using Notepad++, one of my common usage patterns was to take a quick look at a file that was part of some solution that I did not currently have open in a Visual Studio instance.  I'd just find the file in Windows Explorer, right-click on it, and select "Edit with Notepad++" (which is a context menu addition the Notepad++ installer makes that you'll actually find handy rather than annoying).  No long load time, no fuss.

But one of the things I quickly missed that I would have gotten in Visual Studio was syntax highlighting.  For example, if I opened a Web.config file in Notepad++, I wouldn't get any syntax highlighting, because Notepad++ didn't know that *.config files are really XML.

The solution to my problem lied in a very obscure Notepad++ setting that took me a lot of digging to find.

Here's what you do:

- On the Notepad++ menu bar, click "Settings" -> "Styler Configurator..."

screen1
- Under "Language", select "XML"
- Under "User ext", type in "config".  While we're at it, let's also type in (space delimited) "aspx", "ascx", and "master".
- Click "Save & Close"

That's it!  Now when you view config files, ASP.NET pages, user controls, or master pages in Notepad++, you'll get syntax highlighting.

80 comments:

  1. Matt,

    I agree that Notepad++ is a fantasic tool! I use it for coding python documents, php, html, xml and more. It is my default text editor.

    I needed to change the color on some of the highlighting and your Blog helped me find the settings. I looked all over the menus and it was Not where I would expect it.

    Thanks again,
    Dave from Provo, UT

    ReplyDelete
  2. You're welcome, Dave! I'm glad to help. Those Notepad++ settings are definitely not in an obvious place.

    ReplyDelete
  3. Yo, thanks for the idea. I've been trying to figure out how to get highlighting for rhtml files. With your trick, I have Notepad++ highlighting rhtml like it does html.

    ReplyDelete
  4. Thanks man, I could never figure out how to do this. Every time I opened up a .config file, I would go to Language -> XML... EVERYTIME! What a pain.

    You would think that this would be a little bit more intuitive to find.

    In any case, nice job!

    ReplyDelete
  5. I use for editing Notepad++ because is a very complex program and support languages like C; C++; Java; C#; XML; HTML; PHP; CSS; makefile ASCII art (.nfo); doxygen ini file and other. Olso you can edit several documents at the same time. I got it from here: Notepad++

    ReplyDelete
  6. that last comment from yman was pretty dumb

    ReplyDelete
  7. Thanks, just what I needed :)

    ReplyDelete
  8. I was searching for this information allover the web. The association with any new extension should be easier than it is now.

    This setting is not obvious at all in any of the menues of NotePad+++. Thanks for providing this information.

    ReplyDelete
  9. Thanks, exactly what I was looking for :)

    ReplyDelete
  10. It's awesome, and exatly what I've looking for. Great thanks, Matt.

    ReplyDelete
  11. Brilliant! Thanks a lot!

    ReplyDelete
  12. Good stuff! Your post helped a lot.

    ReplyDelete
  13. Very helpful, I looked for a long time and didn't find the setting. Thank you.

    ReplyDelete
  14. Thanks for the tip!

    One quirk I ran into (as of version 5.0.3) is that you must actually close any open files with the new extensions for syntax highlighting to kick in. Simply closing and reopening Notepad++ itself doesn't seem to work.

    ReplyDelete
  15. Thanks for the tip!

    I googled it up today, so sorry for bumping, but I just had to reply!

    ReplyDelete
  16. Thx Matt, great tips on Notepad++ syntax highlighting!

    ReplyDelete
  17. Excellent post! Thanks very much Matt, using the Language menu to select my syntax highlighting every single time was starting to get my back up!

    ReplyDelete
  18. thanks, exactly what I was looking for.

    ReplyDelete
  19. thank you so much. It was such annoying to set color scheme each time I opened ascx files

    ReplyDelete
  20. thanks,just try it and it works.
    btw,found your page when i google for notepad++ syntax highlighting.

    ReplyDelete
  21. Is it only me that prefers to use the ASP highlighting for ASPX pages, rather than XML? Probably because we've got a lot of pages with tons of crappy inline code...

    ReplyDelete
  22. I prefer it highlighting in asp too. For exactly the same reason. I also actually prefer the hightlighting to VS.

    I have also just worked out how to get the auto complete function working for ASP too (notepad++ 5.6.6 supports this). Pretty simple really, just copy a .xml file and a .api file in \Notepad++\plugins\APIs and rename them to asp.api and asp.xml. I used the vb file and combined it with the html file, which means that I get auto completion on my aspx pages now. Most of you probably already know that, but it was a bit of a revelation to me.

    ReplyDelete
  23. Perfect, been searching for this for months

    ReplyDelete
  24. Positively, absolutely, BRILLIANT!

    This should be published on the Notepad++ site!

    ReplyDelete
  25. ya know...that is in the Notepad++ help files.

    ? > Help Content
    Choose Index tab, and search "languages"

    ReplyDelete
  26. Very good tip! Saves me time whenever I open .NET files in NP++ (which is all the time!)

    ReplyDelete
  27. Very nice tip, just what I needed. Thanks!

    ReplyDelete
  28. Thanks! A very simple solution to my aspx problem with Notepad++.

    ReplyDelete
  29. ASPX comment delimiters (<%-- --%>) breaks the XML highlighter

    ReplyDelete
  30. Thanks Matt, this did the trick, I am loving it!

    U DA MA!!!!

    ReplyDelete
  31. You little ripper!! (That means thanks a billion or so)

    This sure beats going Language > HTML or XML!!!!

    I am going to do this on all my NP++ installs I have (work, home, laptop etc)

    ReplyDelete
  32. Cheers Fella you saved me so much time on .config files :-D

    ReplyDelete
  33. Thanks for sharing this.

    ReplyDelete
  34. Thanks a lot, i've been looking for this a long time!

    ReplyDelete
  35. Just what I was looking for, thank you.

    ReplyDelete
  36. Just dropping a comment to say thank you. It was as others have stated not where I expected the option to be.

    Thank you.

    ReplyDelete
  37. Thanks for the tip! Just what I was looking for. I had just had enough of the Language menu for those damned config files that I open constantly throughout the day

    ReplyDelete
  38. Brilliant, just want i needed!

    ReplyDelete
  39. This is great. Thanks friend.

    ReplyDelete
  40. Awesome tip!!!!!!!!! Thank you!!!

    ReplyDelete
  41. Thanks Matt, this is what I've been looking for :)

    ReplyDelete
  42. Thanks for that useful tip.

    ReplyDelete
  43. Thanks so much! I was trying to figure out how to save my files as aspx... this more than helped!

    ReplyDelete
  44. Thank you for this - very helpful even 4 years later. :)

    ReplyDelete
  45. This sounds like exactly what I need, but for some reason didn't work for aspx. Anybody else have that issue?

    ReplyDelete
  46. This comment has been removed by the author.

    ReplyDelete
  47. that a cool trick but you can also in the menu click on
    Language
    A
    asp

    and you have all styling..
    including <% directives

    Jim - to make it work for described xml settings you have to select in npp : Languages/XML

    ReplyDelete
  48. August 2012, and this is still helping! Thanks Matt!

    ReplyDelete
  49. 4 years later, and this helped me with .config files.

    Thanks!

    ReplyDelete
  50. It still works. Thank you!

    ReplyDelete
  51. Brilliant thanks for the tip, you saved me a lot of time!

    ReplyDelete
  52. Five years later this is still helping people. Thanks!

    ReplyDelete
  53. thanks for ur help

    ReplyDelete
  54. This comment has been removed by the author.

    ReplyDelete
  55. Thats a cool trick and it worked....

    You are Awesome man!!!

    ReplyDelete
  56. Thanks a lot for sharing (and being accessible via Google...) !
    Thumbs up!

    ReplyDelete
  57. Thanks a lot for sharing (and being accessible via Google...) !
    Thumbs up!

    ReplyDelete
  58. April 2014 and its still helpful.
    Thumbs up!!

    ReplyDelete
  59. April 2014 and its still helpful.
    Thumbs up!!

    ReplyDelete
  60. Thanks bro, this is gonna help out a lot

    ReplyDelete
  61. This has been bothering me for 2 years now (highlight ASPX as HTML). THANKS!!!

    ReplyDelete
  62. Very helpful! Thanks a lot for posting.

    ReplyDelete
  63. Thanks, Matt!
    Amazing this is still useful considering you posted it almost 7 years ago. Would be nice if it were simply a default syntax config for Notepad++ at this point! But oh, well...

    Thanks for saving me the hour+ trying to figure that one out!

    ReplyDelete
  64. Pfffft.......and on it goes......Yep Matt, this is still the main solution out there.....sad in a way ;) Thanks!

    ReplyDelete
  65. finally, an answer that works! thanks for this.

    ReplyDelete
  66. thank you sir! its very effective.

    ReplyDelete
  67. Did not work today. Got latest version of npp. Followed steps outlined above. Closed npp. Opened npp. Opened "login.aspx" and there was no syntax colorization, etc. Did not work for me. Windows 7. VS 2013. npp latest.

    ReplyDelete
  68. Thanks Matt. This solved my issue.

    ReplyDelete

Note: Only a member of this blog may post a comment.