Setting the default file type for a new file in VS Code

There have been updates since this post!!!!
You can now just use the preference setting files.defaultLanguage to set the default language

Original Post

Just a short post today. When you open a new file in VS Code (Using CTRL + N) it opens by default as a plain text file.

To change the language for the file use CTRL +K, M.

That’s CTRL and K together and then M afterwards separately.

then you can choose the language for the file. It looks like this

01 - Change language

However, if you just want your new file to open as a particular language every time you can change this in the settings.

Click File –> Preferences –> Settings

or by clicking CTRL + ,

02 - Open Preferences.PNG

This opens the settings.json file. Search in the bar for default and scroll down until you see file

03 - File defaults.PNG

If you hover over the setting that you want to change, you will see a little pencil. Click on that and then Copy to Settings which will copy it to your user settings in the right hand pane.

NOTE – You will need to enter powershell and not PowerShell. For other languages, click on the language in the bottom bar and look at the value in the brackets next to the language name

04 - langauge.PNG

Once you have entered the new settings save the file (CTRL + S) and then any new file you open will be using the language you have chosen

It looks like this

05 - Change settings.gif

and now every new file that you open will be opened as a PowerShell file (or whichever language you choose)

You will still be able to change the language with CTRL K, m

Just to be clear, because people sometimes get this wrong. That’s CTRL and K, let go and then M. You will know you are doing correctly when you see

(CTRL + K) was pressed waiting for second key of chord……

06 - waiting for key

If you get it wrong and Press CTRL + K + M then you will open the Extensions search for keymaps.

07 - incorrect.PNG

This is a brilliant feature enabling you to copy key mappings for the programmes you use all the time and save you from learning the Code key mappings. You can find the keymaps in the Extensions Marketplace as well as by pressing CTRL + K + M

6 thoughts on “Setting the default file type for a new file in VS Code

  1. Pingback: VSCode – PowerShell extension 1.4.0 new command Out-CurrentFile | SQL DBA with A Beard

  2. Thanks for the post

    However I can’t see all the details in the .gif pic.
    I this what you inset in user settings?

    {
    “files.associations”: “powershell”,
    }

    Still opens a new file as plain text..

    • You need to follow the instructions of clicking on the pencil and clicking edit and replace in settings to make sure that the formatting is correct rather than entering it directly. Also don’t forget to save 😉
      The correct setting is files.defaultLanguage in the recent versions of vs Code

Leave a Reply to why?Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.