Nam G VU
Nam G VU

Reputation: 35364

How to stop pycharm auto format code after pasted?

In brief

I want to turn off code auto-formation in PyCharm

In full

I often get my comments auto-formatted

from

#my comment

to

# my comment with space inserted

I want to turn this off and found via google this article from JetBrains; though I cannot find the guided option in my PyCharm as snapshots below.

I'm using

PyCharm 2016.2.3
Build #PY-162.1967.10, built on September 7, 2016

enter image description here

Upvotes: 19

Views: 12775

Answers (7)

Carteross
Carteross

Reputation: 11

In addtion to "Reformat on paste" setting to NONE (Editor || General || Smart Keys), you have to also set "Smart ident pasted lines" under Editor || General || Smart Keys || Python

Smart ident pasted lines

Upvotes: 1

Contango
Contango

Reputation: 80192

[File > Settings > Keymap], search for Paste, right click on "Paste as Plain Text", and reassign the key Ctrl-C to it.

Tested with PyCharm 2021.3.2, should work in the latest.

enter image description here

Upvotes: 6

Zack Light
Zack Light

Reputation: 324

For me, I was trying to paste a line of regular non-code text and then use the comment shortcut to comment out the pasted text. PyCharm auto-formats the text to be one line for each word. (It breaks on any white space.) I also only have this problem when I paste on an indented line

The workaround is to always type # and then paste. Or Edit - Paste - Paste as Plain Text. I still consider it a bug.

Upvotes: 1

Amish Ranjan
Amish Ranjan

Reputation: 11

Just go to File>Setting>Save Actions and turn off all actions. Hit apply and you are good to go.See the picture for more info.

Upvotes: 0

Gishas
Gishas

Reputation: 555

Right click - Paste without formatting, this did the trick for me.

Upvotes: 2

Nam G VU
Nam G VU

Reputation: 35364

With PyCharm 2016.3, just use menu command Edit - Paste Simple

Upvotes: 5

matias elgart
matias elgart

Reputation: 1181

look under Preferences -> Editor -> General -> Smart Keys -> Reformat On Paste and set to 'None'. see screen.

enter image description here

UPDATE: looks like the suggestion above didn't work, but i did find another editor setting (python-specific) that will auto-format your code. see attached screenshot. you can get to the setting via:

Preferences->Editor->Code Style->Python near the bottom. deselect the after # setting and try again. this worked for me -- it allowed me to paste the string you had above without having it auto-formatted. HTH

enter image description here

Upvotes: 14

Related Questions