I want to create .HTML file whenever I choose New File, is this possible?
2 Answers
In VS Code, my separate folders for different HTML projects are stored under an UNTITLED (WORKSPACE).
For a new HTML file, I simply right-click on any folder in (WORKSPACE), select New File and then name that file with an HTML extension. The file is completely empty with no HTML whatsoever. Then, because the Emmet plugin is built into VS Code, I simply type an ! (exclamation point) and press TAB or ENTER and the empty file is filed with a complete HTML5 boilerplate.
5 simple steps to create an HTML file in Visual Studio Code
- right-click on folder in (WORKSPACE)
- Select New File
- Name the file with an HTML extension
- Type ! (one exclamation point only)
- Press TAB or ENTER
Comments
As far as I can see, there is no way to configure VS Code to do this out of the box so I wrote an extension to do it. You can download that extension from the marketplace.
It adds two types of commands:
editor.newFile.withCurrentLanguageModewill open a new file with the same language mode as the currently active fileeditor.newFile.withLanguageMode.<languageId>will open a new file with specified id as the language mode. The language must be first added to the configuration and a keybinding set up
So to set up one command to open new html files and another to open markdown files, you can add settings like this:
settings.json:
"editor.newFile.languageModes": ["markdown", "html"]
keybindings.json:
{
"key": "ctrl+shift+t 0",
"command": "editor.newFile.withCurrentLanguageMode",
"when": ""
},
{
"key": "ctrl+shift+t 1",
"command": "editor.newFile.withLanguageMode.markdown",
"when": ""
},
{
"key": "ctrl+shift+t 2",
"command": "editor.newFile.withLanguageMode.html",
"when": ""
}
Using these settings you would then press "ctrl+shift+t" then "0" to open a new file with the same language as whatever file you have active, "ctrl+shift+t" then "1" to open a new file with "markdown" as the language mode, and "ctrl+shift+t" then "2" to open a new file with "html" as the language mode. Of course, you can customize the keybindings however you want and set the languages to whatever you want.
files.defaultLanguagesetting.