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.
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.
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 Wheezy/Jessie/Sid, Linux Mint DE
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.
The importance of not having this extra new line is described at launchpad+question+8787