Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code: End of file new line not persisting

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

like image 534
imyousuf Avatar asked May 03 '18 19:05

imyousuf


People also ask

How do you skip to the end of a line in VS code?

Highlight the row and press ENTER. Press Shift + Space.


3 Answers

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

like image 132
Ahmad Awais Avatar answered Oct 06 '22 18:10

Ahmad Awais


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.

like image 34
imyousuf Avatar answered Oct 06 '22 17:10

imyousuf


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.

like image 32
Henrik Andersson Avatar answered Oct 06 '22 18:10

Henrik Andersson