How to get Sublime Text 3 to automatically highlight CSHTML as HTML

I have a bunch of .CSHTML files that I want to be highlighted. Every time I open a .CSHTML file I have to go to the bottom right of the sublime text window and manually tell it to treat the CSHTML as HTML. How do I force SB3 to automatically do this?


Solution 1:

  1. Open any .cshtml file
  2. In the main-menu, choose View > Syntax > Open all with current extension as… and select HTML

Solution 2:

You can also install syntax packages with Sublime Package Control.

For cshtml/aspx/etc, one option is HTML (C#).

In Windows, if package control is installed

  • Ctrl-shift-p
  • Type "Install Package" (exclusive of quotes)
  • Select Package Control: Install Package
  • Type "html c#"
  • Select extension pictured below to install.
  • Close and reopen files

Picture of HTML (C#) package in sublime

NOTE: This also addresses Nico's comment that mapping to an existing package only highlights html ("a 50% solution") by syntax highlighting the Razor/C# code as well (a 99.44% solution!).