LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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

Reply
 
Search this Thread
Old 04-11-2009, 01:27 PM   #1
sayeo87
LQ Newbie
 
Registered: Apr 2009
Posts: 2

Rep: Reputation: 0
Extra newline at end of file?


Hi,

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.

Would anybody mind explaining this oddity?


Thanks!
 
Old 04-12-2009, 07:09 AM   #2
1337
Member
 
Registered: Apr 2009
Distribution: Slackware-12.2
Posts: 75

Rep: Reputation: 18
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?
 
Old 04-12-2009, 11:00 AM   #3
sayeo87
LQ Newbie
 
Registered: Apr 2009
Posts: 2

Original Poster
Rep: Reputation: 0
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....
 
Old 04-24-2009, 04:06 AM   #4
Raumkraut
LQ Newbie
 
Registered: Apr 2009
Posts: 1

Rep: Reputation: 0
Angry

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.
 
Old 04-24-2009, 04:21 AM   #5
Libu
Member
 
Registered: Oct 2003
Location: Chennai
Distribution: Slackware 12.1
Posts: 165

Rep: Reputation: 36
gedit 2.16 shows the extra new line. Wonder why vi creates/display's it?
 
Old 04-24-2009, 05:07 PM   #6
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 4,052

Rep: Reputation: 484Reputation: 484Reputation: 484Reputation: 484Reputation: 484
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.

jlinkels
 
1 members found this post helpful.
Old 10-30-2009, 05:16 PM   #7
RoboRecht
LQ Newbie
 
Registered: Sep 2009
Location: Belgium
Distribution: Slackware
Posts: 4

Rep: Reputation: 2
in vim

In vim you can type
:set noeol
:set binary
 
1 members found this post helpful.
Old 09-17-2010, 04:45 AM   #8
3r0s
LQ Newbie
 
Registered: Sep 2010
Distribution: Ubuntu, Kubuntu, Xubuntu, Lubuntu
Posts: 4

Rep: Reputation: 0
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
 
  


Reply

Tags
empty, end, extra, file, kate, line, newline, vim


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Extra bytes at the end of class file" when installing WTK2.2 eikeland Linux - Software 1 03-06-2007 08:59 PM
warning: no final newline at the end of /etc/fstab Jeebizz Slackware 2 10-12-2004 02:19 PM
warning: no newline at end of file huno Programming 1 07-16-2004 09:39 AM
[mntent]:warning: no final newline at the end of /etc/fstab Rodcl Linux - Hardware 4 08-25-2002 02:58 PM
Warning: no newline at end of file acid_kewpie Programming 1 03-13-2002 02:53 AM


All times are GMT -5. The time now is 08:33 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration