You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Copy/Cut then Paste doesn't preserve or fix indentation #6392
Copy some divs code in html (with any method "Ctrl + C || Right Click")
Then paste inside other divs
Always have to fix intentation after pasting some code.
Experiencing the same behaviour for css and js.
Reacted by Instagit, crazy_boy, Alex Sokol, Dustin Martin, Lipis, Søren Louv-Jansen, Kai Wood, Vadim Kotov, Mikhail Shustov, Mike Gallagher and 26 more
Having to fix the indentation characters after copy/pasting is really annoying. When you forget it, you end up with a file with mixed indentation. Other editors don't have this problem.
This sounds like you would want some sort of format on paste.
Applying the file's current indentation format to pasted contents would be great.
Reacted by Alex Sokol, crazy_boy, undefined, Søren Louv-Jansen, Jason Merrill, Joao Victor Zanatta, Guillaume Esquevin, CodeWP, Marcelo de Andrade, M and 4 more
undefined (@rubymaniac) The indentation rules we have at our disposal are fuzzy and there are a plethora of languages where they're incorrectly defined. e.g.
if(true)return5;// <-- you probably would like this line to be indentedswitch(a){case5:
return5;// <- same heredefault:
return6;// <- same here}
You will find that these cases do not work correctly in vscode today when pressing Enter and there are probably many languages besides js that have this problem.
Now imagine pasting in proper indented code and the editor indenting it in a wrong way. You would be much more upset than the lack of the auto-indent. That's why I try to take the discussion towards format on paste, as formatting is something that can be provided by a language server, and is not language agnostic (like the indentation rules).
alexandrudima yes I completely agree with what you say about the fuzziness of the indentation rules. However I usually find myself to copy correctly indented code from one place to another with a different offset and VSCode is not adjusting the indentation to the new offset and I always have to do this manually.
For that reason I made a little extension that tries to adjust the offset of the indentation to where the cursor is when you are pasting code.
Reacted by Peter Suter and Eliseu Monar dos Santos
Aha, so you would expect that the pasted code is treated as one blob and indented/unindented as a single blob (all lines the same amount). Makes sense to me.
That would reduce the risk of messing it up, although we'd still need to do per-line adjustments (i.e. detect that the pasted code is indented with spaces@2 meanwhile the file is indented with tabs, etc.).
alexandrudima Exactly what I am saying. The per-line adjustments are crucial in order to do it properly. For what it's worth in the extension I wrote I am making per-line adjustments.
Although the problem is solved (at most cases) through the extension, I feel that this should be native functionality (or at least configurable through preferences).
Peng Lyu (@rebornix) Has just implemented editor.formatOnPaste, so if you are in a language that supports format, the format will be invoked on the pasted content.
Reacted by Instagit, Stephen Davies and Mike Gallagher
I found that hitting CTRL-Z (undo) after CTRL-V (paste) fixes the indentation. Faster to fix, but what extra step is taking place that the CTRL-Z has to undo it? The auto-indent?
Reacted by Ryan, Gibrán Lara, Wesley, Zac Clemans, Florian Imdahl, Ivan Aguilar, Markus W., Ian Lovett and Christian Bueno
Just to drop in my experience, the indention will very occasionally work correctly on paste, but for the most part, I have to use CTRL + Z to get it to the correct level. It seems like it is doing some kind of two step process. I've disabled all my formatting and beautify extensions as well, so it appears to be native.
CTRL + Z works like magic! This particular bug, although minor, can drive you mad if you work with lots of Html code. In fact I've been fighting with this bug for 2 months and couldn't take it any longer! TBH I don't know how other front end devs cope with this vcode peculiarity. Anyway, I'm just glad I landed here coz I've finally found a temporary fix.
Loving the progress of vscode in 2017 though, so even if minor issues like this still exist, I say to you, "Keep up the good work!"
When pasting HTML code indentation is almost always incorrect. CTRL-Z fixes this. What is doing the additional step when pasting?
In regards to the new parameter "editor.formatOnPaste": Should it be true (because it needs a third formatting step) or should it be false (because the mysterious second step will be skipped)?
What worked for me was downloading the extension "Paste and Indent" and once enabled going to my "user settings" ( shortcut CTRL + , ) and pasting in "pasteAndIndent.selectAfter": true into your custom settings.
FYI, "editor.formatOnPaste": true, was not working so I pasted the new PasteAndIndent rule after this
I get this in Typescript, which I thought VSCode focused on as a primary language. An issue since May 16, 2016? Yikes... (people still commenting with this as an issue and it's closed?)
Steps to reproduce:
Copy-Paste a block of callbacks
VSCode automatically indents the pasted code past the start of the copied block
Expected
VSCode pastes the code at exactly the same indentation as the copied block
Activity
wxkin commentedon May 16, 2016
Have you tried to copy/paste it from/at the start of the line?

alx-so commentedon May 17, 2016
wxkin I think it would be inconvenient to always target beggining of the line as you add new, hitting the "enter".
alexdima commentedon May 23, 2016
This sounds like you would want some sort of format on paste.
Instagit commentedon Sep 15, 2016
Having to fix the indentation characters after copy/pasting is really annoying. When you forget it, you end up with a file with mixed indentation. Other editors don't have this problem.
Applying the file's current indentation format to pasted contents would be great.
alanwei0 commentedon Sep 26, 2016
i need this feature too, just like the "paste and indent" function in sublime with
ctrl + cmd + vrubymaniac commentedon Oct 13, 2016
This is a very basic feature to have. Is there any specific reason this hasn't been implemented yet?
alexdima commentedon Oct 24, 2016
undefined (@rubymaniac) The indentation rules we have at our disposal are fuzzy and there are a plethora of languages where they're incorrectly defined. e.g.
You will find that these cases do not work correctly in vscode today when pressing Enter and there are probably many languages besides js that have this problem.
Now imagine pasting in proper indented code and the editor indenting it in a wrong way. You would be much more upset than the lack of the auto-indent. That's why I try to take the discussion towards format on paste, as formatting is something that can be provided by a language server, and is not language agnostic (like the indentation rules).
rubymaniac commentedon Oct 25, 2016
alexandrudima yes I completely agree with what you say about the fuzziness of the indentation rules. However I usually find myself to copy correctly indented code from one place to another with a different offset and VSCode is not adjusting the indentation to the new offset and I always have to do this manually.
For that reason I made a little extension that tries to adjust the offset of the indentation to where the cursor is when you are pasting code.
alexdima commentedon Oct 25, 2016
Aha, so you would expect that the pasted code is treated as one blob and indented/unindented as a single blob (all lines the same amount). Makes sense to me.
That would reduce the risk of messing it up, although we'd still need to do per-line adjustments (i.e. detect that the pasted code is indented with spaces@2 meanwhile the file is indented with tabs, etc.).
rubymaniac commentedon Oct 25, 2016
alexandrudima Exactly what I am saying. The per-line adjustments are crucial in order to do it properly. For what it's worth in the extension I wrote I am making per-line adjustments.
Although the problem is solved (at most cases) through the extension, I feel that this should be native functionality (or at least configurable through preferences).
MacKentoch commentedon Jan 17, 2017
No news?
It is a core functionality to be able to copy/paste without indentation surprises.
VSCode is awesome but I may go back Atom just because of that.
I loose time fixing indentation after a copy/paste...
alexdima commentedon Jan 21, 2017
Peng Lyu (@rebornix) Has just implemented
editor.formatOnPaste, so if you are in a language that supports format, the format will be invoked on the pasted content.14 remaining items
Skura23 commentedon Jul 31, 2017
I find a extension might do this trick:
pase-and-indent extension
I changed ctrl+shift+v of its example configure binds into alt+z, and alt+z works.
neerolyte commentedon Sep 12, 2017
Should pasting without horrible indentation be working in
1.16.0?ejochens commentedon Sep 21, 2017
I found that hitting CTRL-Z (undo) after CTRL-V (paste) fixes the indentation. Faster to fix, but what extra step is taking place that the CTRL-Z has to undo it? The auto-indent?
neerolyte commentedon Sep 21, 2017
Eric Jochens (@ejochens) Nice, that does work.
I logged #34424 as I'm guessing this issue won't be responded to (despite being broken) because it's closed.
zigang93 commentedon Oct 12, 2017
need cmd + Z to fix the indentation too.. any update for this bug?
zaclem01 commentedon Oct 13, 2017
Just to drop in my experience, the indention will very occasionally work correctly on paste, but for the most part, I have to use
CTRL + Zto get it to the correct level. It seems like it is doing some kind of two step process. I've disabled all my formatting and beautify extensions as well, so it appears to be native.Arnique commentedon Oct 13, 2017
CTRL + Z works like magic! This particular bug, although minor, can drive you mad if you work with lots of Html code. In fact I've been fighting with this bug for 2 months and couldn't take it any longer! TBH I don't know how other front end devs cope with this vcode peculiarity. Anyway, I'm just glad I landed here coz I've finally found a temporary fix.
Loving the progress of vscode in 2017 though, so even if minor issues like this still exist, I say to you, "Keep up the good work!"
triplevoid commentedon Oct 23, 2017
Peng Lyu (@rebornix) THANKS! Yes, it is now added it in insider.
Instruction:
Ctrl + , then "editor.formatOnPaste": true property in settings.
taalas commentedon Oct 27, 2017
Still not sure what is happening tbh.
When pasting HTML code indentation is almost always incorrect. CTRL-Z fixes this. What is doing the additional step when pasting?
In regards to the new parameter "editor.formatOnPaste": Should it be true (because it needs a third formatting step) or should it be false (because the mysterious second step will be skipped)?
jlock64 commentedon Oct 27, 2017
What worked for me was downloading the extension "Paste and Indent" and once enabled going to my "user settings" ( shortcut CTRL + , ) and pasting in "pasteAndIndent.selectAfter": true into your custom settings.
FYI, "editor.formatOnPaste": true, was not working so I pasted the new PasteAndIndent rule after this
Hope that helps. This was driving me nuts
ericis commentedon Oct 31, 2017
I get this in Typescript, which I thought VSCode focused on as a primary language. An issue since May 16, 2016? Yikes... (people still commenting with this as an issue and it's closed?)
Steps to reproduce:
Expected
VSCode pastes the code at exactly the same indentation as the copied block
Versions
VSCode v1.17.2
Windows 10 Pro
.editorconfig
./.vscode/settings.json
yveslange commentedon Nov 15, 2017
Installing
pasteAndIndentand adding"pasteAndIndent.selectAfter": trueto the config works