Search code examples
pythonindentationpython-idle

Adding indentation to multiple lines at once in Python's IDLE


I have written many lines of code already, and have now changed my mind on their indentation. (I want to put all of these lines into a 'while' loop.)

For each line, I could press the space button or tab, but this would take a long time.

Can I add the appropriate indentation/margin to all these lines at once?


Solution

  • In Sublime Text, highlight text and press TAB (or SHIFT+TAB to do the opposite i.e. remove one level of indentation). This will do the same as adding a tab at the beginning of every line.

    These shortcuts is the same in several other text editors, e.g. Notepad++, Eclipse and even Word.

    Other editors may use different/additional shortcuts e.g. in CTL+] or CTL+[) in IDLE (and Sublime Text).