Settings to copy paste with correct indentation in

2020-05-11 10:30发布

When I copy and paste a piece of code using Visual Studio Code, after pressing enter to create a new line, the following happens:

enter image description here

It seems to keep the indentation created by the new line, adding the previous information from the copied snippet on top of it. I'd rather the code was auto-beautified on paste.

Can this behavior be changed through settings?

EDIT: I'm not referring to cross-platform copy-pasting, I'm referring to copying and pasting within the same file in Visual Studio Code.

4条回答
混吃等死
2楼-- · 2020-05-11 11:16

This plugin may help you:

paste-and-indent extension

You just have to change the shortcut and it works. Remember that you probably want to use 'cmd' instead of 'ctrl' if you're on a mac. Like this:

{
    "key": "ctrl+v",
    "command": "pasteAndIndent.action",
    "when": "editorTextFocus && !editorReadonly"
},
{
    "key": "ctrl+v",
    "command": "editor.action.clipboardPasteAction",
    "when": "!editorTextFocus"
},
{
    "key": "ctrl+shift+v",
    "command": "editor.action.clipboardPasteAction",
    "when": "editorTextFocus && !editorReadonly"
}
查看更多
▲ chillily
3楼-- · 2020-05-11 11:23

try ctrl+shift+v after copying the code. it will paste all codes correctly with indentations in it. simple fix...

查看更多
啃猪蹄的小仙女
4楼-- · 2020-05-11 11:24

Ctrl-v followed by Ctrl-z seems to work out of the box.

查看更多
Luminary・发光体
5楼-- · 2020-05-11 11:33

This is already integrated in vscode with "editor.formatOnPaste": true property in settings.

查看更多
登录 后发表回答