Gedit adds line at end of file
Asked Answered
R

4

19

The answer to this must be somewhere but I'm not finding it -- can anyone help me understand why in Gedit, if I have a page of code there is no extra trailing blank line, but then when I do a file comparison for my svn commit it shows an extra line being added at the end of the file?

I have a feeling that Gedit is automatically adding an ending line break. But why, I have no idea...

Rives answered 16/6, 2010 at 19:58 Comment(2)
Bug: bugs.launchpad.net/ubuntu/+source/gedit/+bug/379367Era
It's annoying that Gedit also saves after adding the newline, even without asking it to save.Domesday
V
24

Reality finally won and it's been fixed, but the broken behavior is still the default; enable the WYSIWYG behavior in a terminal with

gsettings set org.gnome.gedit.preferences.editor ensure-trailing-newline false
Vitek answered 31/8, 2013 at 7:8 Comment(3)
Ugh, ensure-trailing-newline instead of hide-and-ensure-trailing-newline aaarghMccray
In case you see the dconf-WARNING **: 01:23:35.210: failed to commit changes to dconf: Failed to execute child process “dbus-launch” (No such file or directory) error then (for debian and its friends) run the apt install dbus-x11 command firstGilbreath
... also, looks like this solution doesn't work for ubuntu 22.04Gilbreath
M
6

It's a feature. I don't think it can easily be disabled.

this is intentional: text files should always be terminated by \n, otherwise tools like 'cat', 'sed' etc may have problems. However there is no reason to always show an empty line at the bottom of the text view, that's why we do not show the last \n

paolo borelli [gedit developer]

Mozzarella answered 16/6, 2010 at 20:7 Comment(3)
Thanks. This is unfortunate because I wanted to use gedit but I need to be able to delete that line break in some cases... I wonder if that's possible.Rives
I would like to see a small space at the bottom (even a single pixel) so I can more easily tell the difference between an underscore and a space.Maffick
Feature or not, it's absolutely misleading and counter-intuitive to change file contents without making it visible to the user.Positronium
V
1

Some editors (I'm unfamiliar with Gedit specifically) will try to ensure that a file always ends with a newline character. Other editors, like perhaps the one that you originally created the file with, will allow you to end a file without a final newline character.

Vaccinia answered 16/6, 2010 at 20:1 Comment(0)
R
1

Try the Whitespace Remover plugin.

Roulers answered 1/4, 2011 at 8:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.