user3307629
user3307629

Reputation: 143

PyCharm indentation spaces

How can I change indentation in pycharm to only 2 spaces instead of 4? My team follows the pep8, but chose to use 2 spaces instead of four, and I can't find anywhere to change it.

Upvotes: 14

Views: 24707

Answers (4)

Nathan Wailes
Nathan Wailes

Reputation: 12222

To add to the other answers:

You can also set the number of spaces in an .editorconfig file with indent_size = <some integer>.

enter image description here

I was working on a project for a company and having my Python files indented with two spaces instead of the 4 specified in my PyCharm settings, and it was because of this method of specifying the indentation.

Upvotes: 0

Ilia Kopylov
Ilia Kopylov

Reputation: 788

File -> Settings -> Editor -> Code Style -> Python (or "General" for all text files) -> Tabs and Indents (tab).

And there is a search tool in the top left corner of the settings window. You can use it to search any IDE setting.

Upvotes: 20

IRSHAD
IRSHAD

Reputation: 2933

Please follow the below steps to change the tab/indent size-

  1. Go to File -> Default Settings...
  2. A dialog box will appear, click on Editor -> Code Style -> Python/Other File Types
  3. And set the Tab/Indent size=2 present within right frame.

Below pics will help you more-

enter image description here

Upvotes: 2

Aneesh R S
Aneesh R S

Reputation: 3827

You can set "tab size" to 2 and "indent" to 2. in the File -> Settings -> Code Style -> Python -> Tabs and Indents (tab)

check "Use tab character" in the File -> Settings -> Code Style -> Python -> Tabs and Indents (tab).Now the error or warning message like PEP8: indentation contains tabs will be removed. If the issue exist close the open files and reopen, or simply restart pycharm.

Upvotes: 3

Related Questions