6.4.2 Modify or Create Code Templates

When you create a file to add to your project (5.10.1.1 Step 1. Choose File Type), a template is used for the new file. To change the template, select Tools > Templates, select the template in the Template Manager, and then click Open in Editor to edit the template. You may also use Add or Duplicate in this dialog to create new templates.

New Folder can be used to create a new folder to hold templates. Be aware that MPLAB X IDE filters out all but Microchip Embedded, Shell Scripts, Makefiles and Other, so files or folders should be created under those folders.

Figure 6-37. Template Manager

You may set template options by selecting Tools > Options (MPLAB X IDE > Preferences for macOS), Editor > Code Templates (as shown below).

An option of note for C code is the fcom option. In an Editor window, type fcom and then press the Tab key to insert the following text into the source code:

// <editor-fold defaultstate="collapsed" desc="${comment}">
${selection}${cursor}// </editor-fold>

This option allows you to hide/view sections of code.

In the Code Template tab, selecting fcom will display ${comment} in the Expanded Text section. Hover over this text to see the full text.

Figure 6-38. Template Options