Is there a way to disable copy/paste formatting side effects?

Usually, whenever I paste some code into the editor, it tries to "understand" the context and reformat surrounding code accordingly: indenting/unindenting previous/following lines, etc.

Only it usually does it wrong, and sometimes I only notice when running the (now broken) code. It's OK that the pasted text itself is reformatted, but I didn't want PyCharm to touch the surroundings.

Is there a way to prevent this? I looked at the settings, but couldn't find anything in that regards.

Thanks in advance,
Rubens
2
13 comments
What's your setting for Editor | Smart Keys | Reformat on paste?
0
Avatar
Permanently deleted user
Hi yole,

It is "Indent each line" - I've tried the other options at some point, if I remember well they didn't change this behavior, but I'll try each one of them again, thanks for pointing them.

I did try another setting that seemed to have something to do with it: "Indent pasted lines relative to caret location", but that didn't change the behavior either.

Regards,
Rubens
0
PyCharm 2.6 contains a bunch of fixes related to indent handling when copy-pasting code - could you please give it a try and see if it helps?
http://www.jetbrains.com/pycharm/nextversion/
If it doesn't help, we'd appreciate if you could provide a code example where PyCharm's code formatting is different from what you expect.
0
Avatar
Permanently deleted user
Hi Dmitry,

Thanks for jumping in - good to know that 2.6 is addressing this! I've just seen that it's about to be released, right? I guess I'll wait for it, then, instead of installing the beta version - or do you think it will take longer?

I'll try it again then, and if the problems persist, I'll try to figure out repeatable scenarios to report.

Regards,
Rubens
0
PyCharm 2.6 was just released. Please give it a try and let us know how it works.
0
Avatar
Permanently deleted user
OK, PyCharm 2.6 installed! I turned all the related options again to give it a try.

So far it seems better, the only "flaw" I've found is this scenario:

class MyClass(object):
    member1 = 1
    member2 = 2
    member3 = 3

1) Select "member2" line (let's call it "line 2")
2) Click ctrl-c to copy it
3) While keeping the line selected, hit ctrl-v

It will replace line 2 with itself, as expected, but also unindent line 3! That is the type of behavior I've seen before, not sure if it's still there for some other scenarios, but anyway. This one in particular is not a problem, of course, I'm just reporting since it's similar to what I have observed before...
0
Avatar
Permanently deleted user
Another weird one!

class MyClass(object):
    member1 = 1
    member2 = 2

    member3 = 3

Starting with the above scenario (empty line between lines 2 and 3):

1) Copy some line (e.g.: line 1)
2) Go to the empty line
3) Paste it (ctrl-v)

It will end like this!

class MyClass(object):
    member1 = 1
    member2 = 2

member1 = 1

member3 = 3

Turning the option "Editor -> Smart Keys -> Smart Indent Pasted Lines" off seems to get rid of these behaviors. Not sure what I miss, though.
0
Hi Rubens,

Thanks for your report!
I've created an issue in our bug tracker – http://youtrack.jetbrains.com/issue/PY-7470

Please feel free to vote it and get notified while it fixed.
0
Avatar
Permanently deleted user
Thanks Catherine!
0

Hey Guys, I've been having same issues here and noticed the question isn't answered... how do we DISABLE this behaviour??? I have in Smart Keys the paste settings to None, and it still reformats both the pasted text and the surrounding. sometimes this is done so badly that I'm pasting in a simple text editor. I couldn't find anywhere where I could simply disable this behaviour... it's driving me crazy :(

0
Avatar
Permanently deleted user

Try disabling auto-indenting in the Editor->SmartKeys->CSS section

1

PyCharm 2018.1 is still doing dumb stuff. Even with `Smart indent pasted lines` turned off.

0
Avatar
Permanently deleted user

i disabled "Edit: column select mode" and it fixed my issues

0

Please sign in to leave a comment.