visual-studioidevisual-studio-2022

Prevent VS2022 from removing empty lines in CSS


Every time I edit a .css file and paste a text from the clipboard, VS 2022 removes all empty lines in the block that is being edited.

I can just disable the whole formatting via unchecking “Format on paste” for CSS. But is there a way to keep formatting on without removing empty lines?


Solution

  • The Automatic Formatting doc says,

    When this option is selected, the Code Editor reformats code when you paste it into the editor. The editor uses the currently defined formatting rules. If this option is not selected, the editor uses the original formatting of the pasted-in code.

    Therefore, i guess the way of Format on paste feature works in Visual Studio is that Visual Studio pastes firstly, and then formats the text in various steps. If you don't want disable the "Automatically format on paste" feature, please follow below steps:

    1.Paste the text as normal.

    2.Press Undo (Ctrl + Z) multiple times until all formatting steps have been reverted.