2

This question already has an answer here:

Recently I discovered that, after years of thinking various software was adding a newline to the end of my files, it was actually Pluma (or Gedit - same difference) silently adding them all along. Currently I'm working on a website that will have lots of PHP includes, parsing data saved on disk and the likes, so it would make my life a lot easier to do away with the extra line added to the end of each file. As far as I can tell, there isn't a way to stop this behaviour.

I'd like to either get this sorted or find a text editor similar to Gedit without this issue. I don't really want to resort to using Notepad++ via Wine, but that may be an option. Terminal text editors are also a possibility but I'd rather use one with a GUI for anything more than minor edits to files.

marked as duplicate by karel, user535733, David Foerster, Zanna, Elder Geek Mar 9 '18 at 15:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • In Linux and other Unix-like operating systems non-empty text files end with a new-line character by convention. Do you have a specific reason to break that convention? PHP interpreters should be able to deal just fine with them. – David Foerster Mar 9 '18 at 12:30
  • @DavidFoerster They cause a line break when I'm using PHP includes, reducing markup readability in the output, which I feel is an important aspect during the development process for debugging and the likes. – spacer GIF Mar 9 '18 at 20:21
0

There is a conf in gedit that can correct your problem : You can modify it by typing

gsettings set org.gnome.gedit.preferences.editor ensure-trailing-newline false

If you don't like command line tools You can modify it using dconf-editor (sudo apt install dconf-editor if needed)

Then in dconf-editor go to

/org/gnome/gedit/preferences/editor

And change ensure-trailing-newline to false

  • Is there an equivalent setting for Pluma or should I just install Gedit? I found various settings for Pluma in dconf but none relating to trailing newlines. – spacer GIF Mar 8 '18 at 15:14
  • I have no idea for Pluma, sorry – Félicien Mar 8 '18 at 15:15
  • Gedit doesn't look how I remember. Anyway, this seems to work so I'll use it for my newline-sensitive files. – spacer GIF Mar 8 '18 at 15:37
1

The following editors do not add a trailing newline character, if there is none,

  • leafpad
  • emacs

You can install both via the repositories

sudo apt update
sudo apt install leafpad emacs24

(I checked in 16.04 LTS, and it was the package emacs24 for my emacs.)

Edit:

  • leafpad is a light-weight GUI editor, that comes with Lubuntu.

  • emacs is a classic editor originally from Unix, and it can be run both with a GUI and in a terminal window. It is very powerful, but has a learning curve.

  • Leafpad isn't what I'm looking for. Emacs was a good suggestion, but I don't think I'll be using it. – spacer GIF Mar 8 '18 at 15:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.