Options Window: Editor (Formatting Tab)
To access the Options window, select from the main menu: Tools > Options (Windows® and Linux®)
mplab_ide > Preferences (macOS®)

Tools-Options-Editor-Formatting.png

The Formatting tab in the Editor category controls the editor's automatic code formatting feature. Formatting rules such as the placement of braces, line alignment and spacing can all be specified here. These settings will determine how code is formatted when using features like code templates and the Format command under the Source menu.

Language: All Languages

All-Formatting.png

1

Language

When set to All Languages…

2

Category

3

Properties

These settings for All Languages are overridden by default in the language-specific settings. Changing these values will have no effect unless you uncheck Override Global Options in the language-specific settings (C, C++ and C/C++ Header).

Property Possible Values
Expand Tabs to Spaces Yes/No
Number of Spaces per Indent Number of Spaces
Tab Size Number of Spaces

4

Right Margin

This property determines where the vertical red line is displayed in the editor, indicating what should be the maximum length of a line, specified as the number of characters. This is useful if you want to ensure your code can be printed in the width of a single page or if you are concerned about lines running too long, requiring scrolling to the right to view their ends.

The setting is only a visual cue and does not enforce the right margin, so you can continue typing lines as long as you wish.

If you want to eliminate the red line altogether, set the right margin to 0.

5

Example

The example box provides live, visual feedback as you change properties on the left side of the window. The sample code is displayed, reflecting the settings you specified.

Language: C, C++ and C/C++ Header

C-Formatting.png

1

Language

When set to C, C++, or C/C++ Header you will be presented with an identical set of properties as shown below. Each set of properties are independent of one another, making it possible for C to have completely different settings from C++.

2

Category

The Category box acts as a filter for the Properties grid below. Each section in the Properties grid has a grey heading that corresponds to one of the categories in this list.

3

Override Global Options

Allow properties for this language's settings to override properties in the All Languages settings (enabled by default).

4

Style

This drop-down box lets you choose from a list of style presets for the selected language. Clicking on the Manage button will let you add, modify, delete, or create your own custom style preset.

5

Properties

In this section, you are presented with a list of all the formatting choices that programmers love to argue with each other about. These properties will be applied to a selected file whenever you select from the main menu Source ► Format. They will also be applied to individual blocks of code, added in via the Code Templates mechanism.

Property Possible Values
Indents
Indent Size Number of Spaces
Expand Tabs to Spaces Yes/No
Tab Size Number of Spaces
Statement Continuation Indent Number of Spaces
Constructor Continuation Initializer List Number of Spaces
Preprocessor Directives Indent None
Code
Preprocessor
# at Start Line Yes/No
Indent Namespaces Yes/No
Indent Case Statements in Switch Yes/No
Absolute Label Indentation Yes/No
Indent Visibility None
Half Indent
Keep Extra Spaces Yes/No
Braces Placement
Namespace Declaration Same Line
New Line
New Line Half Indented
Class Declaration Same Line
New Line
New Line Half Indented
Function Declaration Same Line
New Line
New Line Half Indented
Ignore Empty Function Body Yes/No
"switch" Statement Same Line
New Line
New Line Half Indented
Other Same Line
New Line
New Line Half Indented
Multiline Alignment
Function Parameters Yes/No
Function Call Arguments Yes/No
Array Initializer Yes/No
"for" Statement Yes/No
"if" Statement Yes/No
"while" Statement Yes/No
Other Parenthesis Yes/No
New Line
Function Name Yes/No
"catch" Yes/No
"else" Yes/No
"while" Yes/No
Spaces Before Keywords
"catch" Yes/No
"else" Yes/No
"while" Yes/No
Spaces Before Parentheses
Function Declaration Yes/No
Function Call Yes/No
"catch" Yes/No
"for" Yes/No
"if" Yes/No
"switch" Yes/No
"while" Yes/No
Other Keywords Yes/No
Spaces Around Operators
Assignment Operators Yes/No
Binary Operators Yes/No
Ternary Operators Yes/No
Unary Operators Yes/No
Spaces Before Left Braces
Class Declaration Yes/No
Function Declaration Yes/No
Array Initializer Yes/No
"catch" Yes/No
"do" Yes/No
"else" Yes/No
"for" Yes/No
"if" Yes/No
"switch" Yes/No
"try" Yes/No
"while" Yes/No
Spaces Within Parentheses
Function Declaration Yes/No
Function Call Yes/No
Braces Yes/No
Parentheses Yes/No
"catch" Yes/No
"for" Yes/No
"if" Yes/No
"switch" Yes/No
Type Cast Yes/No
"while" Yes/No
Other Spaces
Before Comma Yes/No
After Comma Yes/No
Before Semicolon Yes/No
After Semicolon Yes/No
Before Colon Yes/No
After Colon Yes/No
After Type Cast Yes/No
Blank Lines
Before Class Number of Lines
After Class Header Number of Lines
Before Function Number of Lines
Other
Add leading star in comment Yes/No

6

Example

The example box provides live, visual feedback as you change properties on the left side of the window. The sample code is displayed, reflecting the settings you specified.

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.