Create a new HTML document in Visual Studio Code then paste this:
<body>
<div>
<ul>
<li>Foo</li>
<li>Bar</li>
</ul>
</div>
</body>
Copy the <ul></ul>
statement.
Insert a new line after </ul>
.
<body>
<div>
<ul>
<li>Foo</li>
<li>Bar</li>
</ul>
| <-- cursor
</div>
</body>
... then paste.
<body>
<div>
<ul>
<li>Foo</li>
<li>Bar</li>
</ul>
<ul>
<li>Foo</li>
<li>Bar</li>
</ul>
</div>
</body>
The indentation is completely messed up. A tons of related question are answering this question with:
Disable the
"editor.formatOnPaste": true
, from your settings.
The fact is that I have already disabled this feature. Otherwise I would have got even worse:
<body>
<div>
<ul>
<li>Foo</li>
<li>Bar</li>
</ul>
<ul>
<li>Foo</li>
<li>Bar</li>
</ul>
</div>
</body>
Is there a way to just paste what I copied AS-IS or either get a correct formatting such as:
<body>
<div>
<ul>
<li>Foo</li>
<li>Bar</li>
</ul>
<ul>
<li>Foo</li>
<li>Bar</li>
</ul>
</div>
</body>
Please the Shift+Alt+F is not an answer because it will format the whole document and it requires additional operations.
Currently there is no known stable solution to this. i myself am searching from weeks now. there are some plugins for paste and indent but they raise different issues in many other things like non-responding paste, slow pasting or no multicursor support.
The VSCode forum has this issue as open from years but they arent very active on it. Please go visit the official issue page and try commenting there, every single one counts and we may get official solution to this. https://github.com/Microsoft/vscode/issues/32320
Additionally you can try below plugins, may work for you.
https://marketplace.visualstudio.com/items?itemName=Rubymaniac.vscode-paste-and-indent https://marketplace.visualstudio.com/items?itemName=gazugafan.vscode-indent-on-paste