Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving an empty file creates an additional new line #11044

Open
1 task done
joshuaia opened this issue Apr 26, 2024 · 11 comments
Open
1 task done

Saving an empty file creates an additional new line #11044

joshuaia opened this issue Apr 26, 2024 · 11 comments
Labels
bug [core label] editor Feedback for code editing, formatting, editor iterations, etc setting Feedback for preferences, configuration, etc

Comments

@joshuaia
Copy link

Check for existing issues

  • Completed

Describe the bug / provide steps to reproduce it

  1. Create and open new empty file, for example vim.txt
  2. Don't type anything, just save the file
  3. File will be saved with two new lines inside

Same behaviour in vim mode.

I think there shouldn't be multiple new lines in an empty file.

Environment

Zed: v0.132.2
OS: macOS Sonoma 14.4.1
Memory: 16GB
Architecture: Apple M2

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

No response

@joshuaia joshuaia added admin read Pending admin review bug [core label] triage Maintainer needs to classify the issue labels Apr 26, 2024
@Imgkl
Copy link
Contributor

Imgkl commented Apr 26, 2024

I don't see this behaviour on 0.133.2

@joshuaia
Copy link
Author

Small update, it's important to have ensure_final_newline_on_save=true.

@maxdeviant
Copy link
Member

Just so we're clear, are there two newlines or just two lines with a single newline?

This is what I see:

Screenshot 2024-04-26 at 11 05 32 AM

The above behavior is the expected behavior when ensure_final_newline_on_save is true.

@joshuaia
Copy link
Author

Yes, your reproduction is correct.
I was expecting no newline without content, for example SublimeText doesn't create a newline in that case, and I think it handles such case better, since it makes no sense to have final newline without content of the file.

By the way, vim works this way too: it doesn't create a final newline with no content.
You can check its behavior this way:

  1. Open empty file in Zed and at the same time in vim
  2. Save empty file in vim
  3. Switch back to Zed and you will see there is no final newline
  4. Switch back to Vim and type something
  5. Switch back to Zed and you will see final newline
  6. Switch back to Vim and remove everything, keep only two empty lines (as on your screenshot)
  7. Switch back to Zed and you will see 3 lines in total, since Vim adds final newline by default

@maxdeviant
Copy link
Member

If you change the ensure_final_newline_on_save setting to false does that give you the behavior you want?

@JosephTLyons JosephTLyons added editor Feedback for code editing, formatting, editor iterations, etc setting Feedback for preferences, configuration, etc and removed triage Maintainer needs to classify the issue admin read Pending admin review labels Apr 26, 2024
@joshuaia
Copy link
Author

Yes, if I'm saving empty file.

Here is how it works now:

example.mp4

What I'm expecting:

example2.mp4

@alexkotusenko
Copy link

just add the following line to your settings if you want to disable it: "ensure_final_newline_on_save": false,

@Moshyfawn
Copy link
Member

I believe the OP is aware of the ensure_final_newline_on_save setting, and the point of this issue is to determine whether an extra terminating newline makes sense in the case of an empty file, which doesn't seem to me to be the case, since at least on most Linux systems only a single line is enforced.

@github-actions github-actions bot added admin read Pending admin review triage Maintainer needs to classify the issue labels Nov 5, 2024
@notpeter notpeter removed triage Maintainer needs to classify the issue admin read Pending admin review labels Nov 6, 2024
@deeptechdig
Copy link

zed 0.162.3,
"ensure_final_newline_on_save": false,
this is not working for me on a remote ssh session.
I added this line both in the global section and the host section. A new line is always added.

@injust
Copy link
Contributor

injust commented Dec 28, 2024

My two cents: This is a terrible default. When have you ever needed to save a file with exactly one newline in it?

@esamattis
Copy link

Somewhat related, the ensure_final_newline_on_save: true also removes any extraneous lines from the end of the file. I would not expect it to ever remove lines just add the ending line if it is missing. This causes some unexpected diffs in my git commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug [core label] editor Feedback for code editing, formatting, editor iterations, etc setting Feedback for preferences, configuration, etc
Projects
None yet
Development

No branches or pull requests

10 participants