-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
[FR] Invisible trailing newline should be the default on OSX and Linux #35181
Comments
I agree, we could change the default of But, I would leave the implementation of this as is. i.e. allow the deletion of the last |
Thanks for chiming in and having a look at this issue. But I believe it should not be displayed, for two reasons: 1) displaying it does not add any value (a text file always has a trailing newline, deleting it always brings it back anyway) and 2) it goes against the well-established behavior of traditional Unix text editors. I'm open to hearing use cases where this wouldn't be desired, I myself haven't thought of any yet. As an aside, the only reason I opened this issue was due to this point. I'm a little OCD about trailing whitespace and extraneous newlines. With |
I develop websites with the Backdrop CMS (and previously the Drupal CMS). Both these CMS's have a coding standard that says:
I've therefore been developing code for the last few years in Linux by adding a new line at the end of each of my files. I've just installed VS Code and opened one of my Backdrop files in it. It's displayed as having two new lines at the end of the file. I understand this to be what @cu explains above as follows:
This means I can't do what I'd like to do by setting I hope that makes sense... |
Let's track in #1027 |
Reproduces without extensions: Yes
Description
vscode does not automatically put a newline on the last line of a file in its default configuration. This is much different (and therefore surprising) behavior when compared with virtually all text manipulation tools for Unix-like OSes over the last few decades.
In Unix, a text file is composed of a series of zero or more lines. Each line is terminated by a newline (ASCII
0a
) character. It follows then that unless the file has no characters, a text file should always end in a newline. For a simple example, we can use the shell to create a new file containing a string:Now if we look at the raw byes of the file, we see that a newline (
0a
) was automatically added to the file by theecho
command:This is desireable behavior because if you want to use standard Unix tools to work on the file, they will generally expect all lines to end in a newline whether it's printing the file to
stdout
, combining files, or performing complicated search and replace operations via regular expressions. We can see this in action by printing the file to stdout withcat
:Note that the shell prompt is one line after the file contents. The shell didn't do this, it was the result of the newline at the end of the file.
All other text editors operating in a Unix-like environment append a newline to the last (or only) line in the file. This includes nano, vim, emacs, etc. However, the trailing newline is not displayed and you cannot (normally) delete it. Contrast with vscode which does not append a trailing newline.
Steps to Reproduce
Now open the terminal and print the file to stdout:
Notice how the shell prompt appears on the same line as the contents of the file, indicating the lack of a newline at the end of the file.
Expected behavior
On Unix-based platforms (OSX and Linux), vscode should automatically append a newline to the end of every file as all other text editors for traditional Unix-like systems do. Further, it should not allow the user to see or remove the trailing newline by default, although a setting can be made for users who do want to see it.
I don't know how the Windows platform handles newlines so I defer to others on the platform-specific default behavior there.
Workarounds
There is a setting called
files.insertFinalNewline
but this is set tofalse
by default on Unix-derived platforms. While it solves part of the problem, the final newline is displayed (as an empty line at the end of the file) and can be removed. Although saving the file again always brings it back.The text was updated successfully, but these errors were encountered: