PyCharm Edu 2018.1 Help

Reformatting Source Code

PyCharm Edu lets you reformat source code to meet the requirements of your code style. PyCharm Edu will lay out spacing, indents, keywords etc. Reformatting can apply to the selected text, entire file, or entire project.

It is also possible to apply reformatting to the parts of the source code only, using the formatting markers.

Reformatting the code of a directory

To reformat code for a directory, follow these steps:

  1. In the Project tool window, select the directory you want to apply your reformatting to.
  2. Press Ctrl+Alt+L.
  3. In the Reformat Code dialog box, specify the necessary options and filters for your reformatting and click Run.

Reformatting the code of the current file

To reformat code for the current file, follow these steps:

  1. In the editor of the currently opened file, press Ctrl+Shift+Alt+L.
  2. In the Reformat File dialog, specify options for the reformatting and click Run.

Skipping a region when reformatting source code

To enable formatter markers, make sure to select the checkbox Enable formatter markers in comments in the Markers page of the Settings/Preferences dialog, and type the markers in the Formatter off/on fields.

To skip a certain region on reformatting, follow these steps:

  1. At the beginning of the region, create a line comment (Ctrl+Slash), and then manually type the marker specified in the Formatter off field of Code Style page.
  2. At the end of the region, create a line comment (Ctrl+Slash), and then manually type the marker specified in the Formatter on field of Code Style page.
  3. Perform code reformatting, as described above.

Alternatively, create a live template to surround a block of code with formatter off/on markers, see Live Templates.

Example of using formatting markers

The original source code The code after reformatting
js formatting markers original
When the formatting markers are disabled, the original formatting is broken:
js formatting markers off

When the formatting markers are enabled, the original formatting is preserved:

js formatting markers original
Last modified: 23 July 2018