13

I am facing an irritating problem that no new line is being saved for HTML and JavaScript despite explicitly setting that they should be done. Can someone please guide me what I am doing wrong?

GitHub Project

Visual Studio Code version details:

Version 1.23.0
Commit 7c7da59c2333a1306c41e6e7b68d7f0caa7b3d45
Date 2018-05-03T15:23:19.356Z
Shell 1.7.12
Renderer 58.0.3029.110
Node 7.9.0
Architecture x64

VS Code Settings:

Settings of my Visual Studio Code

mozi_h
  • 41
  • 6
imyousuf
  • 1,245
  • 2
  • 11
  • 15
  • You've shown the user settings. can we assume you have nothing, or nothing conflicting, in your workspace settings? Which override user settings. – Mark May 10 '18 at 18:42
  • 1
    The settings look correct. You can try to run VS Code without the extensions `code --disable-extensions` to make sure that this is not the action of one of the extensions. You can also check whether these settings work in VS Code Insiders (https://code.visualstudio.com/insiders/). – Victor S. May 11 '18 at 11:15
  • @Mark Yes my Workspace settings is completely empty – imyousuf May 11 '18 at 15:52
  • @VictorS. When I start extensions disabled, the end of file new line does work as expected. How do I debug and identify the exact extension causing it? – imyousuf May 14 '18 at 02:15
  • 1
    @VictorS. NVM, I actually started uninstalling the unused extensions and removing a particular one actually solved the problem by uninstalling [this plugin](https://github.com/lonefy/vscode-js-css-html-formatter). Thank you once again. – imyousuf May 14 '18 at 02:28

5 Answers5

27

That's because of a default setting in CODE

  // When enabled, insert a final new line at the end of the file when saving it.
  "files.insertFinalNewline": false,

Turn that to true and you'll be able to persist a new line. I'd also recommend that your turn on the trimmer for more than one new lines at the end.

  • STEP #1: Press + , (CTRL on Windows/Linux) to open settings.
  • STEP #2: Add the following two settings.

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

VSCode.pro setting

⚡ Here's a GIF Demo — Save a file to add a line or trim extra lines

enter image description here

Ahmad Awais
  • 33,440
  • 5
  • 74
  • 56
  • 1
    If you read through the comments in the question and the accepted answer (which I answered on behalf of VictorS and he deserves the bounty IMO, but I can't reward it against a comment); my settings were correct, but a plugin causes that to override (which might be a bug in itself on that plugin). – imyousuf May 15 '18 at 15:48
  • Glad you found it useful :) – Ahmad Awais May 16 '18 at 23:10
  • 1
    How to disable vscode for automaticlly adding newline to js files? I use prettier-eslint – Aflext Apr 28 '19 at 11:41
8

The problem was not in the settings but in the extensions. As pointed out in a comment in the question by VictorS., running the editor in code --disable-extensions I validated that without extensions it does work. Then I started uninstalling extensions until it works and finally zero'd down to this plugin and uninstalling it made things work as I was expecting.

imyousuf
  • 1,245
  • 2
  • 11
  • 15
3

It's the wrong setting.

The correct setting is

"files.insertFinalNewline": false,

setting this to true will enable a new line to be added when saving the file. There is an even more explicit setting "html.format.endWithNewline": false, but I've never used that so I am unsure how it works.

Henrik Andersson
  • 45,354
  • 16
  • 98
  • 92
  • There is no way to update that on the default setting from within the app. When I tried to override it, it sets the new value on the user space (on the right side) – imyousuf May 10 '18 at 13:00
  • @imyousuf that's how VS Code settings, work. When you override it'll be in the User Settings. You can't override the default-default settings. – Henrik Andersson May 12 '18 at 22:28
0

You've set files.eol to be \r\n. I'm no expert, but since you're on Linux, you might want to try the Linux-specific EOL-marker \n. Source

mozi_h
  • 41
  • 6
  • Actually if you notice the default is LF, but since that did not work, I also tried overriding it with CRLF without any luck – imyousuf May 11 '18 at 15:54
0

Go to the extensions in vs code and delete the extension called save on typing and delete it and everything will be good to go

Emilio
  • 41
  • 1
  • 4
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 20 '21 at 18:27