AI, machine learning and deep learning · Introductory

Keyboard Shortcuts

Written by SignalsLab

Early edition: these lessons are being reviewed.

Content

Summary

MATLAB keyboard shortcuts streamline coding by enabling efficient cell execution, code commenting, and autocompletion, thereby reducing reliance on the mouse. These tools help organize scripts into logical blocks and improve readability through smart indentation and automatic formatting.

Intuition

Think of MATLAB shortcuts as a way to keep your hands on the keyboard, saving time and reducing the need to switch between the keyboard and mouse. By using specific key combinations, you can evaluate code in isolated sections, comment out lines quickly, and let the software autocomplete function names, which helps you write cleaner, more organized scripts without constant manual typing.

Derivation

  1. MATLAB provides built-in commands designed to save time and reduce mouse usage.
  2. Users can define new shortcuts via the Home, Preferences menu window.
  3. The software distinguishes between 'Windows defaults' and 'Emacs Default' (used on Mac and Linux), which can be selected in the Home, Preferences, Keyboard, Shortcuts menu.
  4. Shortcuts like Ctrl-Enter allow users to evaluate all code within a highlighted cell without running code outside it.
  5. The Tab key facilitates autocompletion of function, variable, or file names; if multiple options exist, MATLAB provides an alphabetical list.
  6. This feature also works with function inputs, such as cd (change directory) and ls (list files).
  7. Additionally, Ctrl-r comments out selected lines, while Ctrl-t uncomments them.
  8. Ctrl-i performs 'smart indent,' automatically adding spaces to improve the visual organization and readability of nested loops and statements.
  9. The specific behavior of shortcuts depends on the operating system settings chosen in the Preferences menu, where users can switch between Windows and Emacs defaults.
  10. Furthermore, the effectiveness of autocompletion relies on the script being in MATLAB’s path.
  11. Users are advised not to keep their hands on the keyboard too long to avoid repetitive stress-related wrist injuries.
  12. These shortcuts are used within the Editor and Command windows to manage code structure and execution.
  13. For instance, cells are demarcated by a double-percent sign (%%) at the start of a line, allowing code to be grouped into logical paragraphs.
  14. Smart indentation transforms messy code, such as unindented nested for loops, into a visually clean format with proper spacing.
  15. Ctrl-c is used to copy selected text, similar to other programs.

Worked example

Problem

A student has a script with nested for loops that are not indented, making the code hard to read. They also want to test a specific section of code without running the entire script. How can they use shortcuts to fix the formatting and test the section?

  1. Select the unindented nested for loops.
  2. Press Ctrl-i to perform 'smart indent,' which automatically adds spaces to improve the visual organization and readability.
  3. Highlight the specific section of code to test.
  4. Press Ctrl-Enter to evaluate all code within the highlighted cell without running code outside it.

Answer Use Ctrl-i to fix the indentation and Ctrl-Enter to evaluate the highlighted cell.

Common mistakes

  • Using %%% will not create a cell; only %% is valid.
  • Autocompletion requires the file to be in MATLAB’s path.
  • Users may suffer from repetitive stress injuries if they use shortcuts excessively without breaks.

Animation

Animation coming soon

The animated version of this lesson is being prepared for the web. In the Signals AI app, lessons are drawn step by step.

Code

This is a text lesson: it has no animation code yet.

ccBYNC© 2026 SignalsLab. Lesson text shared as is under CC BY-NC 4.0.