How to stop Gedit, Gvim, Vim, Nano from adding End-of-File newline char?

For gEdit Install gEdit there does not seem to be a way to disable having a newline inserted at the end see this answer.

For Vim Install vim (and gVim Install vim) you can - by executing the following option: :set binary. Setting to binary will save the file as is and not insert a newline at the end of the document (Unless there already is one, in which it will be retained). At anytime you can revert this option with :set nobinary.

Nano Install Nano is a little easier. You can launch nano with the -L flag (or --nonewlines if you're more the visual type). This will disable the automatic addition of the newline to the end of the file (so long as one was not actually entered). Ideally you could setup this alias in your ~/.bashrc: alias nano="nano -L", which would launch Nano with the no newlines flag included in it!

Since I don't know exactly what you're doing I'm going to point you to Why should files end with a newline? which may explain why they're there. In short some applications will fail if they don't find an EOL directly before the EOF


For gEdit:

If you are using Ubuntu 12.04 or above, you can set the behavior already.

Through a graphical user interface:

  1. Run dconf Editor (dconf-editor)
  2. Go to orggnomegeditpreferenceseditor
    (or just search for ensure-trailing-newline)
  3. Uncheck ensure-trailing-newline if you don't want automatically added newlines.

On the command line:

  1. Open a terminal (ctrl+alt+T)
  2. enter the following command

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

    and you're done.

Reference | Launchpad bug