Paste without auto-formatting

已回答

I'm working with some complicated code that is indented the way the previous developer liked it, which is adequate to work with, but if I copy and paste a section, it auto-formats it completely changing the indentation and line breaks, making it hard to compare sections for new changes.

How do I stop this? I want a literal exact copy-and-paste and only auto-formatting if I manually do it through my hotkeys.

7

Settings/Preferences | Editor | General | Smart Keys --> Reformat on Paste

Also/Alternative: "Edit | Paste Simple" -- should just paste without any additional auto-actions/improvements on top

6
Avatar
Permanently deleted user

As Andriy mentioned, 'Paste simple', whose hotkey is 'Ctrl+Alt+Shift+V', will preserve the literal whitespace and formatting of the pasted text. That's what I use in these cases.

5

I want to turn it on. Can't find "Settings/Preferences | Editor | General | Smart Keys --> Reformat on Paste"

0

@David Yost

Try search field -- it helps narrowing the stuff a lot:

 

"Help | Find Action..." (Ctrl+Shift+A on Windows using Default keymap) also allows to locate that option even from Welcome screen:

2

"Paste Simple" is not available in pycharm 2022.1.1 professional edition.

Also my reformat on paste is set to None.

Still the formatting seems to change, especially the indentation. Single line code are put in multiple lines.

0

In addition to Settings | Editor | General | Smart Keys | "Reformat on Paste", you need to uncheck Settings | Editor | General | Smart Keys | Python → "Smart indent pasted lines"

3

Thanks to Stian Kristoffer Endresen addition. Alternatively, if you still want to keep smart indent, but not to break lines, you can set "Hard Wrap at" to 999. See the screenshot here: https://stackoverflow.com/a/49557639/7869636

0

请先登录再写评论。