Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I've noticed when I create a generic textfile in vim and have a trailing newline at the end of the file, when I open it with kate it has 2 new lines at the end of the file instead! This is on a fedora machine. The same behavior is observed when I copy the file over to my windows machine and open it in notepad++ (which is able to handle both unix and dos newlines) - 2 newlines instead of 1.
Feeling curious, I tried creating a textfile in vim on my ubuntu machine and used gedit to open it, but surprisingly gedit displayed it correctly - only 1 newline.
It would appear that this is a bug in kate. I wrote a script which reads a file into a byte array and then prints the hex value of those bytes and there is no extra /n inserted (0x0A), however in kate it is showing an extra new line no matter what i do. Maybe someone should submit a bug report?
Hmmm, I don't know. What about the fact that Notepad++ in Windows has the same behavior? The inverse is also true: if I create a file in Notepad++ under Windows and switch it to linux format with 2 newlines at the end, when I move it to a linux machine and open it with vim I only see 1 newline at the end....
Vim and Gedit silently add an extra newline when you use them to save a file. They also hide any final newline from the user, like a dirty secret.
As hinted at, you can expose this behaviour by viewing the file - and the extra newline - in a less deceitful editor: kate, nano, emacs, etc.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
It is a documented vi feature to add a newline to the end of the file.
There are some programs (cron being the most notoriously) which must have a newline at the end of the file. Maybe it is something from the old Unix days where each file had to have a newline at the end to get processed correctly. I am not sure whether that was customary those days.
I tried LeafPad on my Ubuntu Linux and it works like Windows NotePad: no extra new line at the end of the file.
There are people saying that Windows NotePad is one of the worst text editor, but i would say that it just serves the simple purpose to edit simple basic text with no frills and without adding any extra.
On Ubuntu Linux with GNOME desktop i would suggest to use Gedit for general purpose text editing, and LeafPad for editing PHP, HTML, CSS, JavaScript, etc. files.
The importance of not having this extra new line is described at launchpad+question+8787
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.