Command Line Editing
These are time-saving features you can use in the Command Window:
Use the Cut, Copy, Paste, Undo, and Redo features from the Edit menu when working in the Command Window. You can also access some of these features in the context menu for the Command Window.
Recalling Previous Lines
Use the arrow, tab, and control keys on your keyboard to recall, edit, and reuse functions you typed earlier. For example, suppose you mistakenly enter
MATLAB responds with
because you misspelled
sqrt. Instead of retyping the entire line, press the up arrow key. The previously typed line is redisplayed. Use the left arrow key to move the cursor, add the missing
r, and press Enter or Return to run the line. Repeated use of the up arrow key recalls earlier lines.
The functions you enter are stored in a buffer. You can use smart recall to recall a previous line whose first few characters you specify. For example, type the letters
plo and then press the up arrow key. This recalls the last line that started with
plo, as in the most recent
plot function. Press Enter or Return to run the line. This feature is case sensitive. View the buffer of commands from the current and previous MATLAB sessions in the Command History.
MATLAB completes the name of a function, variable, filename, structure, or handle graphics property if you type the first few letters and then press the Tab key. If there is a unique name, the name is automatically completed.
To use tab completion, you must have the tab completion preference selected.
For example, if you created a variable
and press Tab. MATLAB completes the name, displaying
Then press Return or Enter to run the statement. In this example, MATLAB displays the contents of
If there is more than one name that starts with the letters you typed, press the Tab key again to see a list of the possibilities. For example, type
and press Tab. MATLAB does not display anything, indicating there are multiple names beginning with cos. Press Tab again and MATLAB displays
The resulting list of possibilities includes the variable name you created,
costs_march, but also includes functions that begin with
cos. You can continue typing and press Tab again to further narrow the list of possibilities.
Tab Completion for Structures. For structures, type up to and including the period separator, and then press Tab. For example, type
and press Tab to display all fields of
If you type a structure and include the start of a unique field after the period, pressing Tab completes that structure and field entry. For example, type
and press Tab, which completes the entry
mystruct contains no other fields that begin with
Note that the resulting lists from using tab completion might include files that are not valid commands, including private functions.
|Syntax Highlighting and Parentheses Matching||Arrow and Control Keys in the Command Window|