Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

pycharm

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

like image 482
python Avatar asked Jun 21 '13 10:06

python


People also ask

How do I indent the code to left in PyCharm?

In the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Editor | Code Style. Select a language for which you want to configure the indentation. From the options on the right, on the Tabs and Indents, select the Use tab character for the editor to use tabs when you press Tab , indent, or reformat code.

How do you indent multiple lines in PyCharm?

Highlight/ select the lines you want indented, then press TAB as often as needed until they reach the proper indent level. You can remove spaces with SHIFT TAB . You can also use CTRL+ALT+I to auto-indent the selection.

How do I get the Beautify code in PyCharm?

The dialog appears when you press Ctrl+Alt+Shift+L in the editor of the current file. If you choose Code | Reformat Code from the main menu or press Ctrl+Alt+L , PyCharm tries to reformat the source code of the specified scope automatically.

How do I set tab space in PyCharm?

ctrl + shift + A => open pop window to select options, select to spaces to convert all tabs as space, or to tab to convert all spaces as tab.


2 Answers

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

like image 177
yedpodtrzitko Avatar answered Oct 20 '22 14:10

yedpodtrzitko


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.

like image 22
lu5er Avatar answered Oct 20 '22 14:10

lu5er