11

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.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • 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. – Alex Hall Sep 22 '15 at 07: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. – jonrsharpe Sep 22 '15 at 07: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 + [. –  Sep 22 '15 at 07:45
  • 2
    So you do mean IDLE? Then *mention that in the question*. Or just search for it... http://stackoverflow.com/q/1610305/3001761. And IDLE's hardly asceticism, it does have autocomplete! – jonrsharpe Sep 22 '15 at 07: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'? –  Sep 22 '15 at 07:57
  • Yes, that's IDLE - note that if you go to About, it tells you as much. IDLE can have multiple windows open, one containing the "Python Shell" (interactive interpreter) and the others containing `.py` script files. Either way, the point remains that if you look at the options in the menu (Format -> Dedent Region), in common with virtually every other program, it lists the shortcuts for you there. Note also that I do not get rep for edits; that only applies to users with <2k, and that you need to add `@username` for others to get notifications of your comments. – jonrsharpe Sep 22 '15 at 08:05

2 Answers2

19

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
Shubham Sharma
  • 1,753
  • 15
  • 24
13

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.

Psytho
  • 3,313
  • 2
  • 19
  • 27