'How to use pycharm to auto indent the select area by the template of the coding style
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
Solution 1:[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:[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:[3]
CTRL + Shift + L will reformat your code.
Solution 4:[4]
If you happen to use/switch to Mac then the default is is cmd+alt+L
Solution 5:[5]
On Windows 10, keyboard shortcut is Ctrl+Alt+i
The option can be found in Code menu -> Auto-Indent Lines
Solution 6:[6]
As of PyCharm 2020.3.3 the settings for reformatting a specific part of code should be:
CTRL
+ ALT
+ L
For the whole file:
CTRL
+ ALT
+ SHIFT
+ L
Solution 7:[7]
Another shortcut for the latest version 2017.2.3 is: ALT + F8
To view other option go to Code
menu above.
Solution 8:[8]
On Mac OS you can use Option
+ Command
+ L
to reformat/auto-indent the selected area of code. I am using the version 2021.1.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | |
Solution 3 | Paresh Mayani |
Solution 4 | zevij |
Solution 5 | mature |
Solution 6 | Samuel Demir |
Solution 7 | Roel |
Solution 8 | Kundan Kumar |