How to make jetbrains pycharm auto format code on paste

12,973

Solution 1

Edit to keep up to date:

The option Settings | Editor | General | Smart Keys | Smart indent pasted lines will be of interest (Pycharm 2016.3).

Things are always evolving, as a general (and faster) practice, I would recommend to start typing smart indent as soon as the settings window appear. Menus will narrow down to help find where the option sits.

Or even more fancy, Ctrl + Shift + A directly from the editor (search everywhere) can bring you to it.

Solution 2

Short cut for auto formatting: ctrl + alt + L

Share:
12,973

Related videos on Youtube

Ranjith Ramachandra
Author by

Ranjith Ramachandra

Updated on July 12, 2022

Comments

  • Ranjith Ramachandra
    Ranjith Ramachandra almost 2 years

    When I used webstorm and I pasted a bit of code from somewhere else it would do the formatting for me. But with pycharm 3, it is not happening anymore and I have to manually indent the code etc.

    I want to get that feature back. Is there a way to do that?

    • LazyOne
      LazyOne over 10 years
      1) Select your code fragment and Code | Reformat Code... or Code | Auto-Indent Lines ? 2) Check what you have at Settings | Editor | Smart Keys | Reformat on paste P.S. These are just general suggestions, since I'm not a PyCharm user.
  • carrabino
    carrabino over 10 years
    thank you very much. Just so others know, there are 4 additional sub-options, "None" will leave the formatting in tact as you paste.
  • John C
    John C almost 8 years
    PyCharm 5 has it under Settings | Editor | General | Smart Keys | Reformat on Paste, fyi.