How to quickly indent a lot of code when writing python code?

Source: Internet
Author: User
has written a long piece of code, suddenly found that the beginning of the place is missing an if, before all the code is written in the IF, the original use of C directly add two curly braces on the line, now what to do with Python

Reply content:

@ Zhong actually don't need a good editor, is a serious code editor can do this task.

Vim and Emacs do not say, with this will be their own toss. In addition to all the graphical interface of the code editor, including but not limited to visual Studio, notepad++, Eclipse, Sublime Text, GEdit, select you want to indent a piece of code and then press TAB, all lines are indented together If you want to cancel the indentation, Shift-tab will go to the left at the first level.

Also, you used to write C code directly with curly braces do not indent it? Drag out spanking!!!! You don't need to indent when you write C + +? Next time this code can read it?
First of all, there is a good editor, such as Vim, Emacs, Eclipse.
Take Vim for example:
  • Auto Indent: Automatically indents the entire code (GG=G), or indents (=) After a few lines in V mode.
  • Manual indent: v mode selects some rows to be processed, increases indentation (>), or Reduces indentation (<).
Be resolute with pycharm Ah! UltraEdit. Select All: Then press TAB to make a noise. (^ω^) @ Zhong Basically has answered the more comprehensive, I would like to add that in this case, the regular expression is also a common way (to increase the space as a substitution of strings), VIM and its other Ides or editors usually support regular replacement.

Of course, the entire replacement process belongs to the refactoring category, and the Mature IDE and editor (VIM,EMACS, etc.) are supported and can be viewed with relevant help. (VIM with @ Zhong said) I use sublime text, multi-line editing, the whole block indentation, PEP8 format Auto-collation code can be.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.