How to change the language mode of an unsaved file in VS Code

I am a big fan of Visual Studio Code. The shear speed in which it loads makes it my go to editor.  The fact it works on Mac, Linux and Windows is just icing on the cake.

Often I am opening Code so I can make some quick edits to text that I have no intention of saving or want to edit with language support before saving.  For example today I was using Postman to play with the Visual Studio Team Services REST API.  I wanted to take a closer look at the response of a call and possibly save it. When I pasted the raw JSON in Code it looked like this.


Clearly this is not being identified as JSON so any attempts to format this using Shift+Alt+F are going to fail. I need a way to let Code know my file is JSON. Of course I could save the file with a JSON extension and Code would start to treat the file as a JSON file.  But I want it to treat it like JSON even before I save it. Well I pinged the Code team on twitter and they showed me this cool trick.

In the lower right hand corner of the screen is an area to change the Language Mode.


Simply click that area, then select the desired language.


Now when I press Shift+Alt+F my file looks like this!


Comments (7) -

  • Jorge L. María

    1/3/2018 4:10:33 PM | Reply

    Thanks, it's useful in Ubuntu, too!

  • Dennis

    5/9/2018 9:52:42 AM | Reply

    Hi Donovan,

    Some options are so simple that they are easily overlooked. Thanks!


  • Sam Howle

    8/15/2018 8:58:52 PM | Reply

    Thanks! This was very annoying to deal with.

    Also want to add- You can now set a Default Language Mode in your user settings. Just enter the language you want as the default for new files and it will automatically do this. Just make sure to type the language name in lower case (ie- "java") because it appears to be case sensitive. Otherwise, works like a charm.

    • Donovan

      6/1/2019 1:48:03 PM | Reply

      Thanks for the tip about the default language.

  • Chris Leonard

    1/28/2019 3:34:18 PM | Reply

    This is great. I've been choosing "Change Language Mode" in the Command Palette, which is a lot harder to remember. The file type has been right there, easy to change, all along, but I never realized it! This will make changing file (language) types much easier. Thanks again.

  • Fábio Pandolfo

    9/27/2019 7:37:09 PM | Reply

    Thank you very much! Just awesome!!!

  • PF

    7/14/2022 2:19:15 PM | Reply

    This is the greatest article ever written on the internet.

Pingbacks and trackbacks (3)+

Add comment