13

I am using Python 2.7.10 and am having trouble trying to unindent a block of code. Surely there is some sort of shortcut, instead of having to backspace every individual line?

From the Python Shell, I opened a new file (.py) and that's where I am writing the code.

Shift + Tab does not work.

6
  • 2
    What do you mean by the Python Shell? If I run python from the terminal I get a shell in which I can run individual commands but there is certainly no support for editing a file. It's not meant for that. If you want to edit a file nicely use an IDE such as PyCharm. If you want to edit in the terminal use your preferred text editor such as vim. Commented Sep 22, 2015 at 7:34
  • It's not clear what you mean by "in Python". If you mean IDLE, then by default Ctrl-[ dedents - if you go through the menus, they show the shortcuts. Commented Sep 22, 2015 at 7:36
  • From IDLE, if you go File>New File, it shows a blank document, looks exactly a .txt, but it's a .py file. I choose to use this over something like PyCharm as a form of discipline. I feel that if I use PyCharm I will get into the habit of relying too much on its built in features and autocompletes... Thanks for your help, it is Ctrl + [. Commented Sep 22, 2015 at 7:45
  • 2
    So you do mean IDLE? Then mention that in the question. Or just search for it... stackoverflow.com/q/1610305/3001761. And IDLE's hardly asceticism, it does have autocomplete! Commented Sep 22, 2015 at 7:46
  • I don't think it's IDLE, because when I open IDLE off my desktop it opens the Python Shell. From there, I open a new file, and it's blank. Is this 'IDLE'? Commented Sep 22, 2015 at 7:57

2 Answers 2

23

You can unindent using following keys:

In Python IDLE/Spyder: Ctrl + [
In Eclipse: Shift + Tab
In Visual Studio: Shift+ Tab
In PyCharm: Shift + Tab
In Jupyter Notebook: Shift + Tab
Sign up to request clarification or add additional context in comments.

Comments

14

It is Ctrl + [ in IDLE. You can change it to your favorite Shift + Tab in Options -> Configure IDLE - Keys. You need to restart the shell after that.

Comments