![Mac Mac](/uploads/1/1/9/5/119517605/299904075.png)
For those who are new to Visual Studio Code and searching for an easy way to format code on saving, kindly follow the below steps. Open Settings by pressing Cmd+, in Mac or using the below screenshot. Type ' format ' in the search box and enable the option ' Format On Save '. For visual studio code version 1.36.1 (2019) To auto-format the selection, use ⌘K ⌘F (the trick is that this is to be done in sequence, ⌘K first, followed by ⌘F). To just indent (shift right) without auto-formatting, i.e., blindly indent, use ⌘.
My last few articles have focused on using Visual Studio Code to build a series of scripts to help manage Analysis Services data models. As part of this work, I’ve found Visual Studio Code to be extremely helpful in other ways too, such as a very powerful text editor with many features you may find in other advanced text editing tools. So much so, I now use Visual Studio Code as the primary tool I use when working with text files – regardless if any code is involved.
One task in particular I find helpful is to auto format JSON text to either make it more readable, or to identify issues with the structure of the JSON itself – such as missing brackets etc.
Here is a simple example showing how you can create an empty file and paste in some JSON text. Depending on the JSON, the file will auto detect you are working with JSON data, or you need to set the language using the status bar in the bottom right-hand corner.
The animation also shows how you can use the tool to help you fix issues to do with how well-formed the the JSON code is.
The key-map to auto-format the selected JSON is ALT-SHIFT-F.
This is the same key-map to auto-format other languages too, so I often find myself doing CTRL-A (for select all text) followed by ALT-SHIFT-F to fix my messy C# code after a series of cut and paste operations.
Another Visual Studio Code tip
If you find you enjoy using Visual Studio Code to work with text documents, I recommend you ensure the following settings are enabled when you install (or re-install) Visual Studio Code. Once you enabled these check-boxes, you get the option to “Open in Code” when right-clicking a file or folder in Windows Explorer. Essential stuff!
Article Rating
-->Mac Format Atma
Editor behaviors can be set to allow code to be formatted as it is written. These actions are set under Visual Studio > Preferences > Text Editor > Behavior, and some of the more commonly used functions are described below:
- Matching closing braces can be added automatically to code when creating new classes, methods, or properties. When this option is selected, typing
{
will automatically add}
. - On-the-fly code formatting is triggered by character presses, such as semi-colon or braces, which will emulate the formatting preferences that are set.
- You can also choose to format the file when saving it, which allows the writing of code as desired and leaves the IDE responsible for formatting code as set by existing preferences.
- Indentation can be set to None, Auto, or Smart. These do the following:
- None - sets the caret to the start of the next line
- Auto - sets the caret to the same column on the next line
- Smart - indents on the following line based on the code
- Word-breaking behavior differs between OSes, and for navigation purposes, the text editor needs to know where words begin or end. The formatting can be set to Unix or Windows.
Visual Studio Code Mac Format Codes
You can also set formatting rules for XML, CSS, HTML, and JSON.