0

Is there a way to do so? I find a lot of my time is taken up correcting indentation formatting in VSCode after pasting, because it seems to sometimes take the source indenting and apply it at the destination (so the entire pasted code block is at the wrong indent level) or worse, just mess up indents entirely (no idea what's going on here) and I need to manually fix every line.

Example use case, for single PHP files which contain PHP, HTML, and Javascript, I often only want the pasted Javascript block to format nicely. Turning on "paste on format" will format the entire document, often times making the PHP sections awkwardly arranged.

I know that VSCode has "format on paste" in settings, but this formats the entire document. How can I format only the pasted code? Is this even possible?

Thank you

Seltonu
  • 95
  • 1
  • 9

1 Answers1

1

I am not certain whether you're fine with this roundabout solution, but you can format selection with Ctrl+K Ctrl+F (see official vscode site for more detail). So rather than turning on format on paste you can paste and then reselect it and do the shortcut above.

If you're not satisfied with this method, you can try using a vscode extension that was given here under a somewhat similar copy and paste problem

Ping34
  • 206
  • 1
  • 10