imyousuf
imyousuf

Reputation: 1245

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

Upvotes: 13

Views: 15051

Answers (5)

Ahmad Awais
Ahmad Awais

Reputation: 37248

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,
    

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

enter image description here

Upvotes: 28

Emilio
Emilio

Reputation: 61

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

Upvotes: 0

imyousuf
imyousuf

Reputation: 1245

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.

Upvotes: 8

mozi_h
mozi_h

Reputation: 66

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

Upvotes: 0

Henrik Andersson
Henrik Andersson

Reputation: 47222

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.

Upvotes: 3

Related Questions