Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VScode automatically adding new lines on save

I am facing this issue with vscode that whenever I am saving an HTML file it automatically adds the new lines. It is not because of any extension because I tested by starting vscode without extension. Below is what I am trying to say

This is how I want it to be:

    <li><span>X</span></li>
    <li><span>X</span></li>
    <li><span>X</span></li>
    <li><span>X</span></li>
    <li><span>X</span></li>
    <li><span>X</span></li>

And this is what vscode turns it into when I hit ctrl-s

    <li>
        <span>X</span>
    </li>
    <li>
        <span>X</span>
    </li>
    <li>
        <span>X</span>
    </li>
    <li>
        <span>X</span>
    </li>
    <li>
        <span>X</span>
    </li>
    <li>
        <span>X</span>
    </li>

I have turned word-wrap off as well and tried all kinds of settings but no luck yet. Anyone have any idea?

like image 678
Rohit Avatar asked May 08 '18 20:05

Rohit


3 Answers

According to this issue on VSCode's GitHub, There is an option for that since 1.8:

"files.insertFinalNewline": true

And to be thorough, you can use all of these three settings to do most of basic formatting you usually need:

"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,

NOTE: I'm aware that this may not correspond to op's description, although this question is the first hit when searching for vscode append new line on save on DuckDuckGo. So I felt the need to add this answer.

like image 177
Ulysse BN Avatar answered Oct 23 '22 19:10

Ulysse BN


I don't know if this is a bug or what but i toggled this setting "editor.formatOnSave": false to "editor.formatOnSave": true and then again back to "editor.formatOnSave": false and it stopped formatting on save.

It is weird because i did not modify any single setting and now it is working as expected.

like image 45
Rohit Avatar answered Oct 23 '22 18:10

Rohit


For me, disable "JS-CSS-HTML Formatter" extension fixed the problem.

like image 1
Salomon Zhang Avatar answered Oct 23 '22 20:10

Salomon Zhang