Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
[FR] Invisible trailing newline should be the default on OSX and Linux #35181
Reproduces without extensions: Yes
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
Now if we look at the raw byes of the file, we see that a newline (
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
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.
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.
There is a setting called
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...