Py Editor MAC USER MANUALpythoneditor.io ↗ · Version 27.0.3 (33)

Edit code faster

Use the Code and Edit menus to comment, format, complete, duplicate and reshape code without retyping it.

Comment or uncomment a line

  1. Put the cursor on the line.
  2. Choose Code → Toggle Line Comment (⌘/).

A # prefix appears, or disappears if the line was already commented. Press Command-Z to undo and Shift-Command-Z to redo. Comment the whole block you mean to disable: commenting only a function header leaves an indented body behind.

Format Python code

  1. Open the .py file.
  2. Choose Code → Reformat Code (⌥⌘L).
  3. Read the status message under the editor.
  4. Press Command-S to save the formatted file.

Spacing and layout follow Ruff's formatting rules, so images,labels=make_dataset() becomes images, labels = make_dataset(). On an already formatted file the status says the file matches the formatting.

Organize imports

  1. Open the .py file.
  2. Choose Code → Optimize Imports (⌃⌥O).
  3. Check the import block, then save.

Imports are sorted and grouped. This command does not remove unused imports.

Complete a symbol while typing

  1. Type the start of a name, such as describe_da.
  2. Choose Code → Complete Symbol (⌃Space).
  3. Press Return to accept the highlighted suggestion.

The editor offers a local symbol matching the typed prefixOpen the screenshot to view it at full size.

The full name is inserted without parentheses; add the call arguments yourself.

Duplicate a line

  1. Put the cursor on the line, with nothing selected.
  2. Choose Code → Duplicate Line or Selection (⌘D).

A copy appears directly below. With text selected, the selection is duplicated instead.

Move or indent a line

  1. Put the cursor on the line.
  2. Choose Code → Move Line Down or Code → Move Line Up.
  3. Press Tab to indent the line and Shift-Tab to outdent it.

The cursor follows the line. Indentation changes Python structure, so check the whole block afterwards.

Edit repeated text with multiple selections

  1. Put the cursor inside the word you want to change.
  2. Choose Code → Select All Occurrences to select every match in the file, or Code → Add Selection for Next Occurrence (⌃⌘D) to add them one at a time.
  3. Check the highlighted ranges, then type the replacement once.
  4. Press Escape to leave multiple selections.

A function definition and its call selected together in one fileOpen the screenshot to view it at full size.

Every selected range changes together. This matches text, so it can also hit comments and unrelated names, and it changes only the current file.

Insert the same text on several lines

This works in the ACE engine.

  1. Put the cursor at the start position on the first line.
  2. Hold Shift and press Down to reach the last line.
  3. Choose Edit → Toggle Column Selection.
  4. Type the text once.

One typed prefix inserted at the same column on three linesOpen the screenshot to view it at full size.

The text appears at the same column on every selected line. Choose Toggle Column Selection again to return to normal selection.

Grow or shrink a selection

  1. Put the cursor inside a word.
  2. Choose Edit → Extend Selection to select the word, then again to select the whole statement.
  3. Choose Edit → Shrink Selection to step back.

Check the highlight before typing: a larger selection can cover more than you expect.

Change the case of selected text

Select the text and choose Edit → Toggle Case. The selection becomes upper case, and choosing the command again makes it lower case. This is a text change, not a rename, so it can break references to an identifier.

Join two lines

Put the cursor on the first line and choose Edit → Join Lines (⌃⇧J). The next line is joined into the current one. Check the resulting line before saving.

Collapse a function while reading

Put the cursor on the function definition, or select it in Structure, and choose Code → Toggle Fold. The body disappears from view while the definition stays visible. Choose Code → Unfold All to reveal everything again.

Extract an expression or a block into its own name

  1. Select the expression, or the statements you want to move into a function.
  2. Choose Refactor → Extract Variable… for an expression, or Refactor → Extract Method… for statements.
  3. Type a name in the dialog and click Extract Variable or Extract Method.
  4. Check the rewritten code, then press Command-S.

Extract Variable assigns the selected expression to the new name on a line above and uses the name in its place. Extract Method moves the selected statements into a new function and calls it where they were. Cancel leaves the file unchanged. Check the indentation of the result before you save.

Rename a symbol and its references

  1. Put the cursor on the name in its definition.
  2. Choose Refactor → Rename Symbol….
  3. Enter the new name and confirm.
  4. Check the changed files, then save them.

Unlike a text replacement, this updates the symbol's references. It needs a Python language server, described in Find text and jump to code.

Switch the editor engine

  1. Press Command-S in every open document you want to keep.
  2. Open Application Settings → Editing.
  3. Set Editing engine to Native (TextKit) or ACE.
  4. Close Settings and check that the selected file appears in the chosen editor.

The engine applies to every project window. Py Editor saves modified documents before switching and keeps the current engine while any of them is still modified. The Keymap picker is offered only for ACE.