Reputation: 5020
Is there a way in Visual Studio Code to change the default language that is used for new files?
By default if you open a new file, it's set for "Plain Text", I want this to be "HTML" instead.
I am often copy pasting HTML into VSC, editing a bit, then copying it back to a CMS I am using (the CMS editor is horrible). I don't want to save the code on my computer at all, just edit it a bit with HTML syntax highlighting, but I want that to be the default.
Upvotes: 51
Views: 42287
Reputation: 182761
With v1.42 you can either set
"files.defaultLanguage": "${activeEditorLanguage}"
and when you open a new untitled file with an html file as the last active file, the new file will automatically be assigned a languageMode of HTML
.
Alternatively, pasting any html code into a new untitled file from a vscode editor will automatically be detected and the languageMode set to HTML
. Unless you have specifically set
"files.defaultLanguage": "plaintext"
then the languageMode will not be automatically detected as of v1.43.
Also see https://stackoverflow.com/a/68596936/836330 for a preview language detection feature in vscode 1.59.
Upvotes: 12
Reputation: 21
I had a similar issue with VS Code. I wanted to default to Python when opening new files. Solution: Click on File > Preferences > Settings. In the search area, Type: "files.defaultLanguage". Then fill in the language of your choice.
Upvotes: 2
Reputation: 50259
You can now set the default language at either the user or workspace settings level using files.defaultLanguage
:
"files.defaultLanguage": "html"
This can be done as a one off by changing the language mode:
lang
, enterhtml
, enterUpvotes: 71
Reputation: 337
Now you can do this change. Check out "files.defaultLanguage" in settings.
Upvotes: 22
Reputation: 4616
Perhaps you could create a scratch file with the .html
extension? Open that when you need to do some copy/paste editing.
Upvotes: 0
Reputation: 1076
A slightly quicker way to accomplish what Daniel had answered:
html
, then press EnterUpvotes: 6