Documentation Center

  • Trial Software
  • Product Updates

Editor/Debugger Preferences

General Preferences for the Editor/Debugger

You can specify which editor MATLAB® uses, as well as how the MATLAB Editor behaves under various circumstances.

On the Home tab, in the Environment section, click Preferences. Select Editor/Debugger, and then adjust preference options as described in the table below.

PreferenceUsage

Editor

Select which editor you want the MATLAB desktop to use when you edit a file:

  • MATLAB Editor

  • Text editor

If you select Text editor, specify the full path for the editor application you want to use, such as Emacs or vi. For example, c:/Applications/Emacs.exe.

Most recently used file list

In the Number of entries field, type the number of files that you want to appear in the list of recently used files at the bottom of the File menu.

Opening files in editor

Select On restart open files from previous MATLAB sessions if you want the Editor and the files it contained during your last MATLAB session to reopen when you restart MATLAB.

Select Automatically open files when MATLAB reaches a breakpoint to open a running program file when MATLAB encounters a breakpoint in that file.

Automatic file changes

Select Reload unedited files that have been externally modified if you want the Editor to automatically reload the version of a file that you opened and edited outside of MATLAB when the file currently open in the Editor has no unsaved changes.

Select Add line termination at end of file to have MATLAB add a new empty line (sometimes referred to as a <CR>) to the end of a file automatically if the last line in the file is not empty.

Editor/Debugger Display Preferences

You can change the appearance of the Editor.

On the Home tab, in the Environment section, click Preferences. Select Editor/Debugger > Display, and then adjust preference options as described in the table below.

PreferenceUsage
General display option

Select Highlight Current Line and select a color to highlight the row with the cursor (also called the caret).

Select Show line numbers to display line numbers along the left edge of the Editor window.

Select Enable data tips in edit mode to display data tips when you are editing a MATLAB code file. (Data tips are always enabled in debug mode.)

For details, see View Values as Data Tips in the Editor.

Right-hand text limit

Select Show line to display a vertical line with the specified Width and Color at the specified column (Placement) in the Editor.

For details, see Right-Side Text Limit Indicator.

Editor/Debugger Tab Preferences

You can specify the size of tabs and indents and details about how tabs behave in the Editor.

On the Home tab, in the Environment section, click Preferences. Select Editor/Debugger > Tab, and then adjust preference options as described in the table below.

OptionUsage
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 you also select Tab key inserts spaces.

Indent size

Specify the indent size for smart indenting. Smart indenting is one of the Editor/Debugger Language Preferences.

Tab key inserts spaces

Select to insert a series of spaces when you press the Tab key. Otherwise, a tab acts as one space whose length is equal to the Tab size.

Emacs-style Tab key smart indenting

Specifies an indenting style similar to the style that the Emacs editor uses.

Lines indent 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.

Smart indenting is one of the Editor/Debugger Language Preferences.

If you select this preference, you cannot insert tabs within a line.

Editor/Debugger Language Preferences

You can specify how various languages appear in the Editor. MATLAB applies language preferences based on the file extension of the file open in the Editor.

On the Home tab, in the Environment section, click Preferences. Select Editor/Debugger > Language, and then adjust preference options as described in the table below.

    Note:   Not all preferences are available for all languages.

PreferenceUsage
Language

Select the language for which you want to set preferences.

Syntax highlighting

Select Enable syntax highlighting to have the Editor use different colors for different language constructs. Then, adjust the colors you want to use for each language element.

Access color options for the MATLAB language by clicking Set syntax colors.

For all other languages, color options appear under Enable syntax highlighting.

For details, see Syntax Highlighting.

Variable and function renaming

MATLAB Language only

Select Enable automatic variable and function renaming to have MATLAB prompt you to rename all instances of a function or variable in a file when you rename a function or variable.

For details on when MATLAB prompts you, see Automatically Renaming All Functions or Variables in a File.

Comment formatting

MATLAB Language only

In the Maximum column width field, enter the maximum number of characters you want to allow in a line of comments, and then select where you want counting to begin.

Consider selecting:

  • Start from beginning of line when the absolute width of the comments is important. For example, set 75 columns from the start of the line to match the width that fits on a printed page when you use the default font for the Editor.

  • Start from beginning of comment when comments are indented, and you want each block of comments to have a consistent indent and width.

Select Wrap comments automatically while typing to automatically wrap comments at the Maximum column width value when you type comments in an Editor document.

If you clear this option, you can still wrap comments manually, as described in Add Comments to Programs.

Indenting

Select Apply smart indenting while typing to automatically:

  • Indent the body of loops within the start and end of the loop statement.

  • Align subsequent lines with lines you indent using tabs or spaces.

  • Indent functions as specified with the Function indenting format option.

This is called smart indenting. You also can manually apply smart indenting after you type the code.

For more information, see Indenting Code.

Select an option from Function Indenting Format (MATLAB Language only) to specify how functions indent in the Editor, as follows:

  • 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 more information and examples of each indenting format, see Indenting Code.

File extensions

Add one or more file extensions to associate with the Language. The preferences you set for that language apply to all files with the listed extensions.

Editor/Debugger Code Folding Preferences

Code folding enables you to expand and collapse blocks of MATLAB code that you want to hide when you are not currently working on them.

On the Home tab, in the Environment section, click Preferences. Select Editor/Debugger > Code Folding, and then adjust preference options as described in the table below.

For examples and detailed information about code folding, see Code Folding — Expand and Collapse Code Constructs.

OptionUsage
Enable Code Folding

Specifies whether you want code folding enabled for the programming constructs that have their corresponding Enable check box selected.

Enable

Specifies whether you want code folding enabled for the corresponding Programming Construct.

If you select this option for any construct, but clear the Enable Code Folding option, the construct will not have code folding enabled.

Fold InitiallySpecifies whether the corresponding Programming Construct displays collapsed (folded) the first time that you open a MATLAB file.

Editor/Debugger Autosave Preferences

You can specify if, when, and how you want MATLAB to automatically save files that are open in the Editor.

On the Home tab, in the Environment section, click Preferences. Select Editor/Debugger > Autosave, and then adjust preference options as described in the table below.

PreferenceUsage

Enable autosave in the MATLAB Editor

Select to have MATLAB automatically save a copy of the files you are currently editing.
Save optionsSave every n minutes specifies how often you want MATLAB to save a copy of the file you are editing.

Save untitled files saves a copy of new, untitled, files to Untitled.asv.

When there is more than one untitled file, each additional file is saved to Untitledn.asv (where n is an integer value).

For details, see Autosaving Files.

Close options

Automatically delete autosave files directs MATLAB to delete the autosave file when you close the source file in the Editor.

File name

Select the naming convention you want MATLAB to use for autosave files. For example:

  • If you specify Replace with extension: asv, the autosave file for filename.m is filename.asv

  • If you specify Append file name with ~, the autosave file for filename.m is filename.m~

Location

Source file directories specifies that you want autosave files stored in the same folder as the files being edited.

Single directory specifies that you want autosave files stored in a single folder. Specify the full path to that folder and be sure you have write permissions for it.

Was this topic helpful?