Note that for "Untitled" editor ("Untitled-1
", "Untitled-2
"), you now can set the language in the settings.
The previous setting was:
"files.associations": {
"untitled-*": "javascript"
}
This will not always work anymore, because with VSCode 1.42 (Q1 2020) will change the title of those untitled editors.
The title will now be the first line of the document for the editor title, along the generic name as part of the description.
It won't start anymore with "untitled-
"
See "Untitled editor improvements"
Regarding the associated language for those "Untitled" editors:
By default, untitled files do not have a specific language mode configured.
VS Code has a setting, files.defaultLanguage
, to configure a default language for untitled files.
With this release, the setting can take a new value {activeEditorLanguage}
that will dynamically use the language mode of the currently active editor instead of a fixed default.
In addition, when you copy and paste text into an untitled editor, VS Code will now automatically change the language mode of the untitled editor if the text was copied from a VS Code editor:
And see workbench.editor.untitled.labelFormat
in VSCode 1.43.
In March 2021 (possible for VSCode 1.55), issue 118455 "Automatic language classification for Untitled files" and PR 119325 are studying some kind of automatic language detection for untitled files.
And if you forget, with VSCode 1.56, Apr. 2021:
We have noticed that many new users are not aware that a language has to be set in order to get full VS Code language support.
To help with this problem, we have introduced a hint for untitled editors to help users set the correct language mode.
The untitled hint might not be helpful to advanced users, so it goes away immediately as you start typing or you can select don't show to never display the hint again.
With VScode 1.60 (Aug. 2021):
Last release, we introduced an experimental feature for untitled files that would automatically set the language mode for the file based on the contents.
This feature uses machine learning to guess the language and is done entirely on your machine. It's powered by the open-source ML library, Tensorflow.js
, and the ML model from Guesslang by GitHub user @yoeo.
This release we are enabling this feature by default and also expanding the automatic language detection to files that don't have a file extension. In Notebooks, we provide an easy way to ask for language detection using the language picker.
This enables a few fun scenarios:
Grab an example from online and paste it in an untitled editor Language detection of untitled files
"Pipe into code" language detection (showing off detection of extension-less files) Language detection of extension-less files
Auto detect option in Notebooks language picker Language detection of Notebooks
VSCode 1.65 (Feb. 2022) comes with:
When the new setting workbench.editor.historyBasedLanguageDetection
is enabled, untitled editors will use an improved automatic language detection algorithm that factors in your editor history and the contents of the current workspace to provide detection results with much less input text required than before.
Below is an example of using this across JavaScript, TypeScript, Markdown, PHP, and C++ (many more languages are supported):
Theme: GitHub Light + HC Customizations
VSCode 1.70 (July 2022) will propose (issue 152920, PR 153872)
Provide a command to create a new untitled file with a specific language set
Allow to specify language id in command to create a new untitled file
The registerCommandAndKeybindingRule
allows for "New Untitled File args" to add the language ID if known.
That allows for links like [Create Python File](command:toSide:workbench.action.files.newUntitledFile?<args>)
which would create a new untitled file directly for Python language.