| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
Using preferences, you can specify the default behavior for various aspects of the Editor.
To set preferences for the Editor, select File > Preferences > Editor/Debugger. The Preferences dialog box opens showing Editor/Debugger Preferences.

Click the + next to Editor/Debugger in the left pane to view all categories of Editor/Debugger preferences. Select a category and that preference pane displays. Make changes and click Apply or OK.
Click the Help button in the Preferences dialog box for details about Editor/Debugger preferences.
You can also set preferences for the Editor toolbars. Select File > Preferences > Toolbars, and from the Toolbar drop-down list select Editor or Editor Cell Mode, depending on the toolbar for which you want to set preferences.
Select File > Preferences > Editor/Debugger to specify the preferences on the main pane, listed here. Or click the + to see additional Editor/Debugger preferences.
MATLAB Editor. Selecting MATLAB Editor means that the MATLAB desktop uses the built-in Editor.
Text editor. To specify a text editor other than the MATLAB Editor, such as Emacs or vi, to be used when you open an M-file from within MATLAB, select Text editor. Specify the full path for the editor application you want to use.
For example, specify c:/Applications/Emacs.exe in the Text editor field, and then open a file using Open from the File menu in the MATLAB desktop. The file opens in Emacs instead of in the MATLAB Editor.
Note that even if you use another editor, Editor/Debugger preferences are still available because some of the Editor/Debugger preferences apply to other MATLAB tools.
Use this preference to specify the number of files that appear in the list of most recently used files at the bottom of the File menu. You select a file from the list to open it.
On restart. To start a MATLAB session and automatically open the files that were open when you last shut down MATLAB, select the item On restart open files from previous MATLAB session. If the item is not selected and you close MATLAB when there are files open in the Editor, the next time you start MATLAB, the Editor is not opened upon startup.
Reload unedited files that have been externally modified. This option is useful when you edit files in the MATLAB Editor and outside of MATLAB.
With the option selected, the Editor automatically reloads another version of the file as described here. When a file is open in the Editor and the same file is also open outside of MATLAB, the Editor automatically uses the version open outside of MATLAB if you have not edited the file in the Editor.
When you clear this preference, MATLAB displays a dialog box notifying you that the current file was changed outside of MATLAB, and asks if you want to use the latest version.
Add line termination at end of line. With this preference selected, if the last line in the file is not empty, the Editor automatically adds a new empty line to the end of the file. Select this preference if you use your files with other products that expect a new line (sometimes referred to as a <CR>) at the end of the file.
Select File > Preferences > Editor/Debugger > Display to specify these preferences:
See also Desktop Preferences.
Highlight Current Line. Select this preference to highlight the current line, that is, the row with the caret (also called the cursor). This is useful, for example, to help you see where copied text will be inserted when you paste. Then specify the color used to highlight the line.
Show line numbers. Select this preference to show line numbers along the left edge of the Editor window. Showing line numbers allows you to easily use various Editor features, such as Edit > Go To Line. When you clear this item, line numbers are not shown.
Enable datatips in edit mode. Select this preference to see datatips while editing an M-file. By default, datatips do not display while editing (edit mode), although they always display while debugging (debug mode). In edit mode, the datatips display the values of variables in the base workspace, so this is useful for script M-files rather than function M-files. In edit mode for a function M-file, the datatip for a variable displays a value if that variable also exists in the base workspace—the datatip displays the value of the base workspace variable, not the value of the variable in the function M-file.
While you are debugging, you cannot turn off the display of datatips, and they show the value of the variables in the workspace selected in the Stack. For more information about datatips, see Viewing Values as Data Tips in the Editor.
By default, a gray vertical line that is 1-pixel wide appears at column 75 in the Editor to indicate when a line of code becomes wider than desired. You might want to set a right-hand text limit for reasons such as the following:
To prevent the need to scroll from left to right to see an entire line of text in the Editor
To keep each line below a limit imposed by another text editor in which you intend to view the code
To keep each line below a character limit required to ensure that the file will print without cropping text
You might need to print a test page to determine the most appropriate value for the printer printing the file, the margin settings for the printer, and the font size you are using.
Note This limit is a visual cue only and does not prevent text from exceeding the limit. For information on setting a value to automatically wrap comment text at a specified column number, see Formatting Comments in M-Files. |

Show line. Select this preference to display the vertical line in the Editor. Clear it to hide the vertical line.
Placement. Type or select a new value for this field to change the column where the vertical line appears,
The actual column number where you set this preference is most useful when the font preference for the Editor is a monospaced font. In a monospace font, all characters are the same width. See Setting Fonts Preferences for Desktop Tools for details.
Width. Type or select a value for this field to change the width (in pixels) of the vertical line.
Color. Click the down arrow next to the color block to open a palette of colors from which you can choose a new color for the vertical line. Increasing this value might improve the visibility of the vertical line on liquid crystal displays (LCDs) and projectors.
Use cells for testing and publishing code, as described in Using Cells for Rapid Code Iteration and Publishing Results.
Highlight cells. Select this item to highlight the current cell and select a color for the highlighting. Pale yellow is the default color.
Show lines between cells. Select this preference to display a faint gray horizontal line above each new cell. The line does not appear in the published M-file, nor in the printed M-file.
Select File > Preferences > Editor/Debugger > Tab to specify the preferences that follow.
Tab size. Specify the amount of space inserted when you press the Tab key. When you change the Tab size, it changes the tab size for existing lines in that file, unless the Tab key inserts spaces also is selected.
Tab key inserts spaces. Select this item if you want a series of spaces to be inserted when you press the Tab key. If the item is not selected, a tab acts as one space whose length is determined by Tab size.
Indent size. Specify the indent size for smart indenting.
Emacs-style Tab key smart indenting. This indenting convention is based on the style used by the Emacs editor and is similar to the Enable smart indenting preference. With this preference selected, lines are indented according to smart indenting preferences when you position the cursor in a line or select a group of lines, and then press the Tab key. Then, you cannot use tabs within a line.
Information about additional preferences for indenting is provided in these sections:
Setting Language Preferences for additional indenting preferences
Setting Keyboard Preferences for Desktop ToolsSetting Keyboard Preferences for Desktop Tools for function hints, tab completion, and delimiter matching preferences
MATLAB applies language preferences based on the file name extension of the file open in the Editor.
To specify language preferences, such as syntax highlighting:
Select File > Preferences > Editor/Debugger > Language, for the type of file you are editing.
Select the Language.
The preference dialog box displays the preferences for that language. If the language you are using is not an option, it means that setting language preferences for that language is not available.
Change preferences for the language you selected, and then click Apply.
For example, when you edit a file with an .html extension, the language preferences set for XML/HTML apply to that file. If you have a Java file open at the same time, the Java language preferences apply to the Java file.
To specify a file extension associated with the selected language, follow these steps:
Optionally, add or change the file extensions associated with the language in the Language field by using the Add and Remove buttons
Changes you make to the file extensions do not apply to open files until you close and reopen them.
Select a file extension from the File extensions list.
If a file has no extension (for example, a new untitled file), MATLAB treats it as an M-file.
If a file has an extension, but it is not in the File extensions list, MATLAB does not apply any language preferences to that file.
Click Apply.
The following table presents the default file extensions for each language.
Language Preference | Default File Extensions |
|---|---|
MATLAB (MATLAB M-file) | .m (uppercase or lowercase) |
TLC | .tlc |
VHDL | .vhd, .vhdl |
Verilog | .v |
C/C++ | .c, .cpp, .h, .hpp |
Java | .java |
XML/HTML | .xml, .xsl, .wsdl, .html, .htm, .shtml |
For details about preferences for each language, see
Select File > Preferences > Editor/Debugger, and then from the Languages, choose MATLAB to specify these preferences for editing M-files:
See also Setting Preferences for M-Lint.
Select to show colors that help you identify certain constructs, like matching if/else statements.
Click Set syntax colors to open the Colors preference pane, and specify the colors that you want the Editor to use for syntax highlighting.
Clear to show all text in black.
The syntax colors preferences apply to all tools that use syntax highlighting, including the Command Window, the Command History, the Editor and other tools. For a description of syntax highlighting, see Setting Colors Preferences for Desktop Tools.
You can set preferences to have MATLAB automatically apply indenting to your M-file code. The indenting options you specify, however, apply only to lines you enter after changing the preference; they do not affect indenting for existing lines. For information on changing the indenting for existing lines, see Manual Indenting.
Enable Smart Indenting. Select this option to specify that you want:
The body of loops to be automatically indented within the start and end of the loop statement.
The lines you indent using tabs or spaces to result in subsequent lines automatically aligning with the indented line.
Functions to be automatically indented as specified with the Function indenting format option.
After entering a new line, use Text > Decrease Indent to move text back to a previous indent level, if you want.
Although you can manually insert tabs at the start of a line, be aware that smart indenting may not work properly if you do. To correct selected lines, choose Text > Smart Indent.
Deselect Enable smart indenting to specify that you want:
Lines to be aligned on the left by default
To specify indenting manually using the tab and space keys
Functions to not be automatically indented as specified by the Function indenting format option
When you deselect Enable smart indenting you can still indent functions, as specified by the Function indenting format option by selecting the functions in the Editor, and then choosing Text > Smart Indent.
To set the indent size for smart indenting and the tab size for manual indenting, see Setting Tab and Indent Preferences.

Example of Smart Indenting Deselected with Manual Tabs.

Example of Smart Indenting Deselected Without Tabs.

Function Indenting Format. Specify how functions indent in the Editor, as follows:
Select or deselect Enable smart indenting, depending on whether you want your function indenting choice applied automatically, as you type code in the Editor. See Enable Smart Indenting for details.
Choose a function indenting format. The styles for indenting functions are:
Classic — The Editor aligns the function code with the function declaration.
Indent nested functions — The Editor indents the function code within a nested function.
Indent all functions — The Editor indents the function code for both main and nested functions.
For nested functions, provide an end statement at the start of a line for each function declaration.
An end statement aligns with its function declaration only when the end statement appears at the start of the line.
Examples of Function Indenting Format Preference. The following image illustrates each of the function indenting formats.

Specify the Max width, that is, the maximum width, in number of columns, for M-file comments when you select the Autowrap comments preference. The maximum width also applies when you use the Wrap Selected Comments feature. See Formatting Comments in M-Files for details.
For example, assume you select Autowrap comments and set the maximum width to be 75 characters, which is the width that fits on a printed page using the default font for the Editor. When typing a comment line, as you reach the 75th column, the comment automatically continues on the next line.
See also the Right-Hand Text Limit preference for the Editor/Debugger.
See File Extensions for general Language preferences.
Target Language Compiler (TLC) is an integral part of Real-Time Workshop®. Select File > Preferences > Editor/Debugger > Language > TLC to specify these preferences for editing TLC files:
See also Setting Preferences for M-Lint.
Select the Enable syntax highlighting check box to show colors that help you identify TLC constructs, such as commands and macros. Optionally, change the colors used for these elements.
Commands. Color for TLC commands, such as LibBlockMatrixParameter.
Comments. Color for the comment indicator, %% or /%...%/, and its associated text.
C Strings. Color for C strings.
See File Extensions for general Language preferences.
Select File > Preferences > Editor/Debugger > Language to specify these preferences for editing VHDL files:
Select the Enable syntax highlighting check box to show colors that help you identify certain VHDL constructs, such as keywords and operators. Specify the colors used for these elements.
Keywords. Color for VHDL keywords, such as SIGNAL.
Comments. Color for the comment indicator, -- , and its associated text.
Operators. Color for operators, such as <=.
Strings. Color for strings, such as "0000".
See File Extensions for general Language preferences.
Select File > Preferences > Editor/Debugger > Language to specify these preferences for editing Verilog files:
Select the Enable syntax highlighting check box to show colors that help you identify certain Verilog constructs, such as keywords and operators. Specify the colors used for these elements.
Keywords. Color for Verilog keywords, such as assign.
Comments. Color for the comment indicator, // , and its associated text.
Operators. Color for operators, such as =.
Strings. Color for strings, such as "Test Completed'.
See File Extensions for general Language preferences.
Select File > Preferences > Editor/Debugger > Language to specify these preferences for editing C or C++ language files:
Select the Enable syntax highlighting check box to show colors that help you identify certain C constructs, such as methods. Specify the colors used for these elements.
Show methods. Text style for methods to appear in when you type them: Bold, Italic, or Plain (no special highlighting).
Keywords. Color for keywords, such as if.
Strings. Color for terms enclosed in double quotation marks, for example, "default".
Characters. Color for terms enclosed in single quotation marks, for example, 'a'.
Comments. Color for text following the comment indicator, //, as well as for the block comment indicators, /* and */, and the code in between.
Preprocessor. Color for text following the preprocessor symbol, #.
Bad characters. Color for illegal characters.
You can set preferences to specify if you want MATLAB to automatically apply indenting to your C/C++ files. The indenting options you specify, however, apply only to lines you enter after changing the preference; they do not affect the indenting for existing lines. For information on changing the indenting for existing lines, see Manual Indenting.
Enable Smart Indenting. Select this option to specify that you want:
The body of loops to be automatically indented within the start and end of the loop statement.
The lines you indent using tabs or spaces to result in subsequent lines automatically aligning with the indented line.
After entering a new line, use Shift+Tab to move text back to a previous indent level if you want.
Although you can manually insert tabs at the start of a line, be aware that smart indenting may not work properly. Use the Text menu entry for Smart Indent to correct selected lines.
Deselect Enable smart indenting to specify that you want:
Lines to be aligned on the left by default
To specify indenting manually using the tab and space keys
To set the indent size for smart indenting and the tab size for manual indenting, see Setting Tab and Indent Preferences.
For examples see:
See File Extensions for general Language preferences.
Select File > Preferences > Editor/Debugger > Language > Java to specify these preferences for editing Java files:
See also Setting Keyboard Preferences for Desktop Tools for the Editor/Debugger and Command Window and Setting Language Preferences.
Select the Enable syntax highlighting check box to show colors that help you identify certain Java constructs, such as methods. Specify the colors used for these elements.
Show methods. Text style for methods to appear in when you type them: Bold, Italic, or Plain (no special highlighting).
Keywords. Color for keywords, such as if.
Strings. Color for terms enclosed in double quotation marks, for example, "alive".
Characters. Color for terms enclosed in single quotation marks, for example, 'a'.
Comments. Color for text following the comment indicator, //, as well as for the block comment indicators, /* and */, and the code in between.
Bad characters. Color for illegal characters.
Select or deselect Enable smart editing to specify whether you want the Editor to apply indenting to your Java files when you press the Enter key to type in a new line. The effects are the same as those for C/C++ files. For details and examples, see the C/C++ preference for indenting.
See File Extensions for general Language preferences.
Select File > Preferences > Editor/Debugger > Language > XML/HTML to specify these preferences for editing XML, XSL, WSDL, HTML, HTM, and SHTML files:
Select the Enable syntax highlighting check box to show colors that help you identify XML, WSDL, and HTML constructs, such as elements and tags. Optionally, change the colors used for these items.
Attribute Name. Color for attribute names.
Attribute Value. Color for values, such as the source for an image, for example "myimage.gif", in <img src="myimage.gif">.
CDATA Section. Color for a CDATA section in XML files.
Character. Color for characters and entities, such as the nonbreaking space,  .
Comment. Color for text contained within comment indicators, <!-- and -->.
DOCTYPE Declaration. Color for DOCTYPE declarations.
Error. Color for invalid entries, such as <+1> for font size, which is deprecated in favor of style sheets in the HTML 4.01 specification.
See the W3C Web site http://www.w3.org/TR/html4/ for details.
Operator. Color for operators, such as the equal sign (=).
Processing Instruction. Color of the instructions to the application that processes the XML file.
Tag. Color for tags and elements, such as <font> or <img>.
Select or deselect Enable smart editing to specify whether you want the Editor to apply indenting to your files when you press the Enter key to type in a new line. The effects are the same as those for C/C++ files. For details and examples, see the C/C++ preference for indenting.
See File Extensions for general Language preferences.
Select File > Preferences > Editor/Debugger > Code Folding to set these preferences for hiding and revealing code in M-files, including function and class code, function and class help code, programming control blocks, and so on.
See also Appearance of an M-File — Making Files More Readable, and Working with M-Files.
Select this option to enable code folding in M-files; clear this option to disable code folding in M-files. (Use the table that appears below this option to enable and disable code folding for selected programming constructs within an M-file.)
This option has the following effects:
If you select this option, code folding is enabled for all programming constructs that you enable in the table that appears below this option in the Preferences dialog box.
If you clear this option, code folding is disabled for all programming constructs, regardless of the programming constructs that you may have previously enabled in the table that appears below this option in the Preferences dialog box.
If you select the Enable code folding for M-files option, you can independently enable or disable code folding for individual programming constructs (function code, function help, programming control blocks, class code, and so on) by selecting or clearing the Enable check box that corresponds to each construct in the table on the Preferences dialog box. By default, code folding is enabled for all programming constructs except if/else blocks and switch/case blocks.
If you enable code folding for a programming construct, you can specify how the Editor displays that construct the first time that you open an M-file that existed prior to MATLAB version 7.5. Select or clear the Fold Initially check box associated with a construct to direct the Editor to collapse or expand the associated construct, respectively, the first time you open an M-file that existed prior to MATLAB version 7.5 (R2007b) using MATLAB version 7.5 or later.
Select File > Preferences > Editor/Debugger > Autosave to specify these preferences for the Editor's autosave feature.
The MATLAB Editor automatically saves a copy of the current version of the file you are editing. Clear this check box if you do not want the MATLAB Editor to save the copy automatically.
Save every n minutes. Specify how often you want the Editor to save, automatically, a copy of the file you are editing.
Save untitled files. Select this check box if you want the Editor to save automatically a copy of new files that you have not yet saved, which are therefore untitled. If selected, the first autosave file is Untitled.asv. If the folder already contains a file named Untitled.asv, the autosave file is Untitled2.asv, and so on, for additional unnamed files.
If the autosave feature creates Untitled.asv and you later save the file as filename.m, the next autosave version is filename.asv. Untitled.asv remains until you delete it.
Automatically delete autosave files. With this preference selected, MATLAB deletes the autosave file when you close the source file in the Editor.
Specify the extension used for autosave files. The default setting for Microsoft Windows platforms is the extension .asv (for autosave), making the autosave file filename.asv. For Microsoft Windows and UNIX platforms, you can select Replace extension with and specify any extension.
For UNIX platforms, the default is Append file with the tilde (~) character, making the autosave file filename.m~. For Windows and UNIX platforms, you can select Append file with and specify a different string to append to the file.
Specify the full path for the folder where you want autosave files stored. You can specify a single folder for all autosave files, such as a folder you create called autosave_files. For the Editor to create an autosave file, you must have write-permission for the specified location.
If you do not specify a location, MATLAB:
Stores the autosave file for each named file in the same folder as the source file, that is, the file you are editing.
Stores the autosave file for each untitled file in the folder that was the current folder when you opened the file.
Additional information that relates to the Editor and preferences includes:
![]() | Starting, Creating Files, and Closing the Editor | Entering Statements in the Editor | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |