How to remove the line breaks that’s added in the formatting when saving the code in VSCode
For example:
If I have an expression with multiple validations:
if True == True or False == True or False == False:
It is being formatted as:
if (True == True
or False == True
or False == False)
This complicates readability. How can I reformat it to look like the first example?
2
Answers
First check to see which formatter VSCode is using to format your code. In most cases (I tried Black and Ruff), you can disable the formatting of a specific piece of code by wrapping it inside the below block:
Without that comment, it would put them in single line.
I guess most formatters will respect that comment.
You can use the shortcut
Ctrl+,
to open the settings. Inputformat on save
and deselect theEditor:Format On Save
option. This disables the use of code formatting when saving documents globally. This preserves the format of the code you wrote it.