How to use pycharm to auto indent the select area by the template of the coding style

44,300

Solution 1

That action is called Reformat code. You can find it in Code menu, somewhere in the middle, or use the hotkey CTRL + Shift + L

Solution 2

The latest version of PyCharm uses CTRL + SHIFT + ALT + L in both Linux and Windows. Then from the reformat dialog box, choose what reformatting option you want to perform.

Solution 3

CTRL + Shift + L will reformat your code.

Solution 4

If you happen to use/switch to Mac then the default is is cmd+alt+L

Solution 5

On Windows 10, keyboard shortcut is Ctrl+Alt+i

The option can be found in Code menu -> Auto-Indent Lines

Share:
44,300
python
Author by

python

Updated on March 17, 2021

Comments

  • python
    python over 3 years

    Well, In eclipse, I can set the code-style template , when the code finish, I could indent it by the template. For example,

    In the coding style template, I set the style is as following:

    aDict = {1: 'a', 2: 'b'} ## that is each variable got a whitespace in front of it

    If I write the code like this

    aDict = {1:'a',2:      'b'}
    

    How can I indent the code after I wrote it?

    I tried the "code-Auto Indent Lines", which is binding to Hot-Key "Ctrl + Alt + I",but It seems doesn't work

  • Krachtwerk
    Krachtwerk about 10 years
    On Windows it's [Ctrl] + [Alt] + [L]
  • radtek
    radtek over 8 years
    How do you disable the Auto-Indent Lines when you Reformat Code? It seems to run every time now, where before I could set it as a separate in a dialog.
  • Roel
    Roel over 6 years
    it is ctrl + shift + alt + L
  • Magoo
    Magoo over 3 years
    If you don't know the shortcut don't post