Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Visual Studio Code use Emmet completion in razor .cshtml files

I'm using Visual Studio Code (1.17.1, on MacOS 10.13 AND Windows 10) developing an asp.net core mvc web app using razor templating. Visual Studio Code supports Emmet (https://code.visualstudio.com/docs/editor/emmet)

My issue is that Emmet works correctly in HTML files, but will not work in razor CSHTML files.

I've found:

To enable the Emmet abbreviation expansion in file types where it is not available by default, use the emmet.includeLanguages setting. Make sure to use language ids for both sides of the mapping. https://code.visualstudio.com/docs/editor/emmet

but it doesn't indicate where to find a list of "language ids". I tried searching for it, but you can imagine what happens when you search for programming language id!

Is there a way to tell Emmet in VS Code to treat cshtml files as html files? Is there any other way to get this to work (besides renaming the files, which is another solution out there)?

like image 375
JamesDuff Avatar asked Oct 11 '17 12:10

JamesDuff


People also ask

Does VS Code support Emmet?

Support for Emmet snippets and expansion is built right into Visual Studio Code, no extension required.

How do you integrate Emmet code in Visual Studio?

Open the VS Code settings (Code → Preferences → Settings) and search for “Emmet Extensions Path”. Click “Add Item”, enter the path to the folder where you've saved the snippets. json file you've created earlier and press “OK”.


2 Answers

According to this link, the corresponding language for *.cshtml files is razor, thus you need to specify it in the emmet mappings as follows:

"emmet.includeLanguages": { "razor": "html" }

like image 161
Rene Hernandez Avatar answered Sep 18 '22 16:09

Rene Hernandez


updated: Press Ctrl+K than M (Ctrl+K,M) than select highlighter from the dropdownlist you want this is a common shortcut. very useful. even works for any file types. ie. create a new file and code some xml or what language you want than Ctrl+K,M you can specify/override ide hilighter on the fly. very useful shortcut. try it. you won't forget Ctrl+K,M. one of most useful hotkey combination I ever use in vscode. by this way code-completion wakes up and works as language you selected.

in vscode > settings.json
I added the related codes mentionel above. emmet worked for cshtml files.

 "emmet.includeLanguages": {
   "razor":"html",
   "aspnetcorerazor":"html"
  }
like image 23
Zen Of Kursat Avatar answered Sep 17 '22 16:09

Zen Of Kursat