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.

image

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.

image

Simply click that area, then select the desired language.

image

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

image

Add comment

Loading