Toolbar, Interface, and Shortcuts of the Editor in the MPLAB® X IDE

Last modified by Microchip on 2024/06/24 06:31

This section discusses the MPLAB® X Integrated Development Environment (IDE) user interface and various shortcuts (keyboard, toolbar, etc.).

Editor Toolbar

The MPLAB X IDE toolbar provides a range of capabilities to facilitate the development, testing, and debugging of embedded applications. It can be customized by right clicking on the toolbar. There are many predefined arrangements that can be customized to your preference. The following section describes an example of various functions available for the toolbar. Please refer to your version of MPLAB X IDE for available options. 

MPLAB X Editor Toolbar

Edit History

MPLAB X IDE Last Edit Icon

Last Edit

Jumps to the location of your last edit and moves the cursor to that line. Hitting this button repeatedly will cycle through all edits in the current session.

MPLAB X IDE Back Icon

Back

Jumps to the location of the previous edit in your edit history and moves the cursor to that line.

MPLAB X IDE Forward Icon

Forward

Jumps to the location of the next edit in your edit history and moves the the cursor to that line.

Search

MPLAB X IDE Find Selection Icon

Find Selection

Searches for other occurrences of whatever text is currently selected in the editor.

MPLAB X IDE Find Previous Occurrence Icon

Find Previous Occurrence

After clicking on the Find Selection button, this will find the previous occurrence (upward) of the selected text in the editor. 

MPLAB X IDE Find Next Occurrence Icon

Find Next Occurrence

After clicking on the Find Selection button, this will find the next occurrence (downward) of the selected text in the editor. 

MPLAB X IDe Toggle Highlight Search Icon

Toggle Highlight Search

After clicking on the Find Selection button, this turns on or off the highlighting of other occurrences of the selected text in the editor. 

Bookmarks

MPLAB X IDE Previous Bookmark Icon

Previous Bookmark

Jumps to the previous bookmark (up) in the current file and moves the cursor to that line.

MPLAB X IDE Next Bookmark Icon

Next Bookmark

Jumps to the next bookmark (down) in the current file and moves the cursor to that line.

MPLAB X IDE Toggle Bookmark Icon

Toggle Bookmark

Creates or removes a bookmark on the line of the cursor's current position.

Indent

MPLAB X IDE Shift Line Left Icon

Shift Line Left

Reduces the indentation

MPLAB X IDE Shift Line Right Icon

Shift Line Right

Increases the indentation

Macros

When you have repetitive tasks that you perform frequently, macros can save you quite a bit of time. 

MPLAB X IDE Start Macro Recording IconStart Macro Recording
MPLAB X IDE Stop Macro Recording IconStop Macro Recording

Comments

MPLAB X IDE Comment Icon

Comment

Comments out one or more lines of code around the cursor's current position or multiple highlighted lines.

MPLAB X IDE Uncomment Icon

Uncomment

Uncomments an entire block comment surrounding the cursor's current position. 

Back to Top


Glyph Margin

The glyph margin is the vertical bar on the left side of the MPLAB X IDE editor window that typically displays line numbers. In addition, various glyphs (icons) will occasionally replace the line number to provide status information.

MPLAB X Glyph Margin

GlyphDescription
MPLAB X IDE Current Program Counter (PC) Location GlyphCurrent Program Counter (PC) location
MPLAB X IDE Error GlyphError
MPLAB X IDE Warning GlyphWarning
MPLAB X IDE Bookmark GlyphBookmark
MPLAB X IDE Suggestion GlyphSuggestion/Hint
MPLAB X IDE Line Breakpoint GlyphLine Breakpoint
MPLAB X IDE Disabled Line Breakpoint GlyphDisabled Line Breakpoint

Hovering the mouse pointer over a glyph will cause a tool tip to pop-up explaining the details behind the glyph's appearance.

MPLAB X Glyph Hover

Back to Top


Configure the Tab Key

MPLAB X IDE permits custom configurations for the tab key. These can be assigned default values appropriate for a specific programming language or can be fully customized to your preference. 

In this example, the tab key will be configured for the C language and show options for additional settings. 

From the main menu select Tools > Options.

Tools Options window

Back to Top


Select the Editor icon MPLAB X IDE Editor Icon along the top of the window.

tab settings in the editor

Back to Top


Select the Formatting tab. This is where the global Tab options are located. However, if you are programming in C, the C language-specific settings by default will override any selection made here. Continue to the next step if you are programming in C.

formatting tab options

Back to Top


Immediately under the Formatting tab, select C in the Language combo box. Tab settings for C language files are found under the Indents category in the properties grid on the lower left of the window.

c language option under the formatting tab

Back to Top


Code Folding

What is code folding?

Code folding is a feature of the MPLAB X IDE editor that makes it possible to collapse (hide) and expand parts of a file, making it easier to focus just on the parts of interest. In general, any code block surrounded by braces { and } will be collapsible. This includes function bodies, compound statements, and groups of compiler directives. Code folds may be nested, providing a high degree of control over which parts of a file are visible at any one time. Code folding is configurable to include or exclude numerous code structures and also provides a means of creating custom code folds to hide and reveal any part of a file you desire.

How to Use Code Folding

On the far left of the editor window, immediately to the right of the glyph margin, you will see some small boxes with either a + or a - inside them. When a block is expanded, you will see a - that may be clicked to collapse the code. Likewise, when the code is collapsed, clicking on the + will expand it.

Function Unfolded

unfolded function

Function Folded

folded function

How to Configure Code Folding Options

General code folding is enabled by default, but many of its features are not. To change code folding options (or disable it altogether if you are so inclined) do the following:

Go to the menu Tools ► Options.

In the window that opens, select the Editor icon MPLAB X IDE Editor Icon from the top.

Back to Top


Select the Folding tab.

Back to Top


Check or uncheck each item under the Code Folding section as desired.

code folding options window

Back to Top


Code Assistance

Code Assistance is a feature that analyzes the first few characters you have typed and provides a list of possible endings. For example, if you are using a library with a series of functions that start with lcd, after typing in those letters, you will see a list of functions such as lcdInit() and lcdWrite() displayed for you to select from.

To activate the Code Assistance window:

In the editor, type in the first few letters of an identifier (e.g. variable or function name).

Back to Top


Press the keys Ctrl + Space (you may need to do this twice).

Back to Top


When activated, you will be presented with a list of all identifiers (macros, variables, functions, etc.) that start with those letters. Double-clicking on any item in the list will add it to your code by completing the text you started to type in.

Selecting an item in the list (single click) displays a documentation window that by default will have nothing in it. You need to provide the content for this window using specially formatted comments in your code.

Once you have inserted a new function, a tool tip will appear to prompt you for any required parameters. If there are multiple parameters, the next one to be entered will be highlighted with bold text.

Code Documentation

The Code Assistance window can display documentation for the selected identifier.

code assistance window

To create documentation for a function, you need to add a Javadoc comment block immediately above the function prototype (or definition if available) that starts with /** on the first line. The editor can assist you by auto-populating a basic Javadoc comment block.

To add a documentation comment with the editor's assistance:

Type in the following sequence of characters on the line immediately above the item you wish to document: /**

Back to Top


Press Enter

The editor will automatically add a skeleton for the documentation similar to the one shown (if documenting a function).

/**
*
* @param num
* @param radix
*/

void lcdPutInt(long num, char radix);

On the first line with a *, you can type in a description of the function. The @param lines were added automatically based on the parameter list of the following function prototype. You can add comments after each parameter on the same line and they will also appear in the documentation window.

The documentation shown in the image above was generated by the following comments immediately above the lcdPutCur function declaration.

/**
* Positions the cursor on a character LCD module at the specified row and column, both of which are zero-based.
* @param row Row number of the display, where the top row is 0.
* @param column Column number of the display, where the leftmost column is 0.
*/

void lcdPutCur(char row, char col);

Javadoc formatted comments can be considerably more complex. Comments may be formatted as HTML which can then be used to generate documentation in the form of web pages. For more details on the syntax and capabilities of this feature, please see the Oracle website's page on the topic.

Back to Top


Code Assistance Options

Enable or Disable Automatic Display of Code Assistance

From the main menu, select Tools > Options.

Click on the Editor icon at the top of the window, then select the Code Completion tab. Check or uncheck the options to suit your needs.

Code completion tab

Find Matching Brace

Put the cursor next to one brace, then hit Ctrl + [ (Ctrl and left square bracket) and the editor will move the cursor to the matching brace and if necessary, scroll the editor to make it visible.

Keyboard:

Ctrl + [

MPLAB X IDE Find Matching Brace Example

Back to Top


Select Between Braces

Put the cursor next to one brace, then hit Ctrl + Shift + [ (Ctrl and Shift and left square bracket) and the editor will select (highlight) all code between matching braces.

MPLAB X IDE Select Between Braces Example

Back to Top