49

I occasionally need to go line-by line and change the indentation of the code.

Is there a shortcut in Pycharm where I can add spaces (format the indent) in the begining of multiple lines simultaneously without processing each line individually?

7 Answers 7

87

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.

6
  • But what if the TAB makes 8 spaces instead of 4 which is what intended? Is there anyway to force it to move forward only by 4 spaces?
    – Rebel
    Commented Apr 30, 2018 at 20:53
  • 1
    @Allan Tab Size is a setting under Settings -> Code Style -> the language you are using Commented May 2, 2018 at 21:45
  • 2
    ctrl+alt+i is possibly the most useful keyboard shortcut I've ever learned.
    – Kevin
    Commented Sep 13, 2018 at 4:08
  • 1
    ctrl+alt+i doesn't work on my Windows machine, but TAB does.
    – mikey
    Commented Nov 23, 2020 at 20:48
  • What if you want to add spaces that don't end up like CTRL + ALT + I ends up? as in if CTRL ALT I adds three spaces and I wanna add 4? Commented Feb 11, 2022 at 11:19
19

Select the block that you want to indent then press TAB. It will work.

5

To auto indent all the codes in Pycharm just press these sequencies:

CTR + A to select all the text files and then press

CTRL+ALT+I

1
  • What if you want to add spaces that don't end up like CTRL + ALT + I ends up? as in if CTRL ALT I adds three spaces and I wanna add 4? Commented Feb 11, 2022 at 11:21
1

Select all that you want to indent, then do CTRL+ALT+I to indent all of it. This should work in Pycharm

1
  • What if you want to add spaces that don't end up like CTRL + ALT + I ends up? as in if CTRL ALT I adds three spaces and I wanna add 4? Commented Feb 11, 2022 at 11:21
1

Use shift +alt on windows machine

0

Continuation indent for Mac pro: Preferences -> Editor -> Code Style -> the language -> Tabs and Indents

0

If Ctrl + ALT + I is not working and every time needs to press the Insert button to get the pointer.

So go to Tools -> Select Vim if it is checked then it will be disabled.

Now you can intend code directly selecting multiple lines.

Not the answer you're looking for? Browse other questions tagged or ask your own question.