BlueCaret
BlueCaret

Reputation: 5020

Change VSCode Default Language for new files?

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

Answers (6)

Mark
Mark

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

Syl Koffi
Syl Koffi

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

Daniel Imms
Daniel Imms

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:

  1. F1 to launch command palette
  2. Type lang, enter
  3. Type html, enter

Upvotes: 71

BeerRider
BeerRider

Reputation: 337

Now you can do this change. Check out "files.defaultLanguage" in settings.

Upvotes: 22

Bob Rockefeller
Bob Rockefeller

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

scrthq
scrthq

Reputation: 1076

A slightly quicker way to accomplish what Daniel had answered:

  1. Press Ctrl+K, then M
  2. Type html, then press Enter

Upvotes: 6

Related Questions