Editor#
Spyder’s multi-language Editor pane is the core element of the IDE, where you can create, open, and modify source files. The Editor offers a variety of core features, such as autocompletion, real-time analysis, syntax highlighting, horizontal and vertical splitting, and much more. In addition, it integrates a number of powerful tools for an easy to use, efficient programming experience.
Key components#
The Editor pane consists of the following areas:
The left sidebar shows line numbers and displays any code analysis warnings that exist in the current file. Clicking a line number selects the text on that line, and clicking to the right of it sets a breakpoint.
The scrollbars allow vertical and horizontal navigation in a file.
The context (right-click) menu displays actions relevant to whatever was clicked.
The options (“hamburger”) menu at the top right includes useful settings and actions for the Editor.
The location bar at the top of the pane shows the full path of the current file.
The tab bar displays the names of all opened files. It also has a Browse tabs button (at left) to show every open tab and switch between them—which comes in handy if many are open.
Interface#
Tabs#
You can browse and navigate between open files in the Editor with tabs. Click the Browse tabs button on the left of the tab bar to display a list of open files, with the active tab checked.
Reorder tabs by dragging and dropping, or with Sort tabs alphabetically in the options menu, which also allows closing all tabs to the left, right, or all but the active one.
File switcher#
The Editor features a file switcher, accessed from the menu or via the Ctrl-P shortcut (Cmd-P on macOS). This allows browsing a list of files open in the Editor and present in your current project, if one is opened; click any file to jump to it.
You can type any part of an open or project file’s name and the list will be filtered accordingly; pressing Enter will give focus to or open the currently-selected file, respectively.
Note
Including all files from the current project in the search is supported when Spyder is installed via our recommended standalone installers or via Conda, but not via Pip.
Split panels#
The Editor can be split horizontally and vertically into as many distinct panels as desired. This allows viewing and editing the contents of several files (or different parts of the same file) at the same time.
Split the Editor with the Split vertically (Ctrl-Shift-{) and Split horizontally (Ctrl-Shift--) commands in the options menu, and use Close this panel (Alt-Shift-W) to close the selected split panel.
Note
closes a split panel, while hides the entire Editor pane (including all splits, which are restored when the Editor is re-opened).
Editing features#
Syntax highlighting#
To improve the readability of your code, Spyder has a syntax highlighting feature that determines the color and style of text in the Editor, as well as in the IPython Console.
You can configure and preview syntax highlighting themes and fonts under . The Syntax highlighting theme section allows you to change the color and style of the syntax elements and background to match your preferences. You can switch between available themes in the drop-down menu, modify the selected theme, create a new theme, and more. The Fonts section lets you change the interface and code font and size.
Note
If Automatic is selected in the Main interface section, changing the syntax highlighting theme from dark to light will automatically change Spyder’s overall interface theme to match.
Code cells#
A “code cell” in Spyder is a block of lines, typically in a script, that can be executed all at once in the current IPython Console. This is similar to “cell” behavior in Jupyter Notebook and MATLAB. You can divide your scripts into as many cells as needed, or none at all—the choice is yours.
You can separate cells by lines starting with either:
# %%(standard cell separator), or# <codecell>(IPython notebook cell separator)
Providing a description to the right of the separator will give that cell its own name in the Outline.
You can also create “subsections” by adding more % signs to the cell separator, e.g. # %%% to create a level 2 subsection, # %%%% for level 3, etc.
This displays as multiple hierarchical levels in the Outline pane.
Note
This only affects how the cell is displayed in the Outline, and doesn’t affect running it in the Editor.
To run the code in a cell, use , the Run cell button in the toolbar or the keyboard shortcut (Ctrl-Enter/Cmd-Return by default). You can also run a cell and then jump to the next one—letting you quickly step through multiple cells—using , its corresponding toolbar button or the Shift-Enter keyboard shortcut.
Automatic formatting#
The Editor has built-in support for automatically formatting your code using several popular tools, including Autopep8, Black and Ruff. The Format file or selection with {tool} command in the Source or context menu will format either the selected fragment (if text is selected) or the entire active file.
You can have the Editor automatically format your files every time you save them. To set this up, go to and check the Autoformat files on save option.
Running code#
The Editor lets you run an entire file as well as specific lines, selections or cells.
As your code is running,
The IPython Console will display output and errors.
The Variable Explorer allows you to browse and interact with the objects generated.
The Plots pane renders the figures and images created.
Run file#
Run an entire Editor file using the menu item, the Run file toolbar button or the F5 key. Use to re-run the most recent script executed with the above.
Run line/selection#
You can execute the current line—or multiple selected lines—using the Run current line/selection option from the toolbar or the menu, as well as with the F9 key (by default). After running the current line, the cursor automatically advances to the next one, so you can step through your code line by line. Unlike Run file, the executed lines are shown in the IPython Console.
Run cell#
To run a cell, place your cursor inside it and use the menu item, its corresponding toolbar button or the Ctrl-Enter / Cmd-Return keyboard shortcut. Use Run cell and advance in the Run menu/toolbar or Shift-Enter to jump to the next cell after running, useful for stepping through cells quickly.
Run configuration#
You can use the Run configuration dialog to set each file’s working directory, console mode (current, dedicated or external), command line arguments, execution options (clear all variables, run in an existing/empty namespace, debug on error), and more.
To access it, click or press Ctrl-F6 / Cmd-F6. The Runner drop-down allows to configure settings for the different runners capable of executing your files, including the Debugger, Profiler, Code Analysis, as well as running in an external system terminal. To configure settings for running in the default IPython Console, select IPython Console. The relevant options for each runner can be set under Custom configuration, and you can save them as presets by giving them a Name and clicking OK. You can then switch between different presets from the Preset configuration dropdown below the Runner selection.
Code analysis and completions#
Spyder uses the Language Server Protocol (LSP) to provide code completion and linting for the Editor, similar to VSCode, Neovim, and other popular editors/IDEs.
Note
Many issues with completion and linting are outside of Spyder’s control, and are either limitations with the LSP or the code that is being introspected, but some can be worked around. See Completion/help not working for troubleshooting steps.
Python is supported out of the box, and advanced users can add completion and linting support for other languages by setting up LSP servers for them under .
Code completion#
Automatic code completion as you type is enabled by default in the Editor, and can also be triggered manually with Ctrl-Space/Cmd-Space, showing you possible completions (with pop-up help for each) and available code snippets.
For example, typing cla will display the keyword class, the decorator classmethod and two built-in snippets with class templates.
Select the desired completion with the arrow keys and Enter, or by double clicking.
You can enable or disable on-the-fly code completion, as well as modify when it is triggered and what results are shown, under . Spyder also allows you to define custom completion snippets to use, in addition to the ones offered by the LSP, under .
Linting and code style#
Spyder can optionally highlight syntax errors, style issues, and other potential problems with your code in the Editor, which can help you spot bugs quickly and make your code easier to read and understand.
The Editor’s real-time linting warns of syntax errors and likely bugs in your code. It is on by default, and can be disabled or customized under . The linting providers available include:
Pyflakes (default), which detects basic errors.
Flake8, which incorporates error checks, code style linting and complexity analysis.
Ruff, which includes a huge variety of configurable lint rules covering a wide gamut of possible issues in your code.
Flake8 and Ruff enable a default set of checks that aims to strike a balances between catching errors and potential problems, and issuing too many warnings, with Spyder additionally disabling some style-related checks by default. You can override these defaults or enable or disable any specific categories or individual checks using the Show/Ignore these errors or warnings fields and the rule prefix/numbers listed in their respective documentation (they use the same set of codes for the same checks, aside from a few cases where two third-party Flake8 checks have conflicting codes). You can also ignore or only check specific files by name or regular expression using the Only check these filenames and Exclude these files or directories options.
Introspection features#
If there’s a function, class or variable for which you would like to check its definition, hold Ctrl/Cmd and click its name in the Editor to jump to the file and line where it is declared.
You can hover over the name of an object for pop-up help, as described in the Help pane docs.
Finally, if you type the name of a function, method or class constructor and then an open parenthesis, a calltip will pop up which shows the function’s parameters as you type them, as well as a summary of its documentation. These features can be enabled and customized under .
Keyboard shortcuts#
To view the Editor’s primary keyboard shortcuts, consult its section under . The full list can be browsed, searched and customized (on double-click) in .